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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Invalid length parameter
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

United Kingdom
17 Posts

Posted - 03/01/2014 :  04:19:17  Show Profile  Reply with Quote
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.

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

In (Som, Ni, Yak)

17689 Posts

Posted - 03/01/2014 :  04:39:54  Show Profile  Reply with Quote
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

Time is always against us

Go to Top of Page

Starting Member

United Kingdom
17 Posts

Posted - 03/01/2014 :  04:49:24  Show Profile  Reply with Quote
It did!

Perfect, thanks khtan
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000