Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Invalid length parameter

Author  Topic 

Kerryman
Starting Member

17 Posts

Posted - 2014-03-01 : 04:19:17
Hi Guys, the statement below is producing the following error;

'Invalid length parameter passed to the LEFT or SUBSTRING function.'

I think I need an ISNULL clause but I'm struggling with the syntax, appreciate it if someone could point me in the right direction.


SELECT
[Contract], WkComm,
SUBSTRING(TuePMWork, 0, CHARINDEX(' ', TuePMWork, 0)),
SUBSTRING(TuePMWork, CHARINDEX(' ', TuePMWork, 0) + 1, LEN(TuePMWork) - CHARINDEX(' ', TuePMWork, 0))
FROM REGULARIZED_AM
WHERE 0 < CHARINDEX(' ', TuePMWork, 0)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-01 : 04:39:54
it didn't handle situation where SPACE is the last character.

LEN() does not includes the last character. See
select	LEN('abc '), DATALENGTH('abc ')


So changing to DATALENGTH() should fix it


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Kerryman
Starting Member

17 Posts

Posted - 2014-03-01 : 04:49:24
It did!

Perfect, thanks khtan
Go to Top of Page
   

- Advertisement -