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
 General SQL Server Forums
 New to SQL Server Programming
 Invalid length parameter passed to the substring f

Author  Topic 

challapavan
Starting Member

8 Posts

Posted - 2007-08-13 : 10:42:17

Hi there when i tried to execute the following query in sql server

select au_fname,
SUBSTRING(P1.au_lname, CHARINDEX('/', P1.au_lname) + 1,
CHARINDEX('=', P1.au_lname, 1)-3)AS [Full Name]
from authors as P1

i will get the error like
"Invalid length parameter passed to the substring function."

If i remove -3 from there it works fine...
Please can anyone clarify this issue.

Thank You.

pavan

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-08-13 : 10:44:21
when charindex() function cannot find the '=' in the string au_lname, it returns 0.


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

Go to Top of Page

ashley.sql
Constraint Violating Yak Guru

299 Posts

Posted - 2007-08-13 : 10:47:36
whats wrong with this

select P1.au_fname, P1.au_fname+' '+ P1.au_lname
as [Full Name] from Authors as P1

why are you trying to do it that way

Ashley Rhodes
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-14 : 01:50:01
Can you post some sample data with expected outcome?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -