Hello!!
I have a column name sender_index_code in a table called action_taken. now i ma trying to search into the table using sender_index_code.
Some values of sender_index_code are like
5/2012-D-prog
7/2011-U-sec
16/2012-R-secids
now i am letting user enter only the number part and search the table like when user enter 5/2012 he will be shown the records for the sender_index_code 5/2012-D-prog.
for this i am using this query
select * from action_taken where substring(sender_index_code,1,charindex('-',sender_index_code,0)-1) ='5/2012'
but it shows me error that
Invalid length parameter passed to the LEFT or SUBSTRING function.
how ever when i am breking this query into two pasts for test purpose in my sql server they are working fine.
for example i first find the char index of '-'.
select CHARINDEX ('-','5/2012-D-prog',0)-1
here i have used -1 because i want to get values fore the '-'
then use this char index to extract string before the first '-'
select SUBSTRING('5/2012-D-prog',1,6)
abd it gives me the right answer i.e 5/2012 but the whole query as a whole is not working