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 2000 Forums
 Transact-SQL (2000)
 Issue with substring

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-10-12 : 14:18:01
When I execute this query Iam getting an error.Please can somebody suggest me what is wrong
Server: Msg 536, Level 16, State 3, Line 1
Invalid length parameter passed to the substring function.

SELECT F.inc_id,NULL,NULL,
SUBSTRING(G.issue_desc,1,CHARINDEX(':', G.issue_desc, 1)-1)as Test,
SUBSTRING(G.issue_desc, CHARINDEX(':', G.issue_desc, 1)+1, len(G.issue_desc))as Test2 ,
G.grade,
G.considered_by

FROM tbl_info_master F,
tbl_issue_master G
WHERE F.inc_id=G.emp_id

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-12 : 14:24:00
there is a record where CHARINDEX(':', G.issue_desc, 1)=0

so that would be a length of -1

Corey
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-10-12 : 14:24:47
IS PATINDEX a solution for this case
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-12 : 14:49:49
what case are we talking about? Show me some sample records, and the desired result. I have a feeling patindex won't be necessary...

Corey
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-10-12 : 15:06:02
Got it thanks I used case statement to chek the condition u told me so now it works fine ..Thanks a lot seventhnight...
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-12 : 15:34:01
no problem... glad i could help

Corey
Go to Top of Page
   

- Advertisement -