Click here to Skip to main content
15,892,005 members

Response to: Problem with substring

Revision 3
Thats because if charindex is not present then substring will become 0-1 =-1 but the index itself starts from 0 and no element would be at -1 index.

For eg, if 5/2012D is one of the value, then in substring function it becomes
substring(sender_index_code,1,(0-1)) and it will throw error
try
SQL
select * from action_taken where '5/2012'=
 CASe when charindex('-',sender_index_code,0)>0 then  substring(sender_index_code,1,charindex('-',sender_index_code,0)-1)
else ''
end
Posted 3-Oct-12 21:29pm by Santhosh Kumar Jayaraman.