I have a stirng in one c开发者_JAVA技巧olumn. Column Name is PreviousStageIDs. In this column I have a String data as 12150, 13250. I want to run SQL statement to seprate 12150 using quama as condition. Means in this string when quama found then sql must take all the data before quama. Help me in this matter.... Thank in advance.
JAY....
12150 is not fix one time it is 12150 second time it will be 14830. I wan to take only that string which is before comma.
JAY
If I understand the (edited) question, you want to find all rows where the first substring in comma-delimited column PreviousStageIds = '12150'. For that you would use the SUBSTRING() and CHARINDEX() functions.
If substring '12150' can occur anywhere in the string, not just as the first substring, then you have to use LIKE operator with wildcards, and a quick kludge is to prepend and append a comma to the string:
... where ',' + PreviousStageIds + ',' LIKE '%,12150,%'
You may also need to trim extra spaces from the string.
Storing a comma-delimited list in a relational database is usually WORST PRACTICE.
精彩评论