Reputation: 65
Below is my Table XYZ data
Sno ProgramID ProgramName
1 1,2 CCE
2 3,11 DDU
I want output like below passing programID 1
Sno ProgramID ProgramName
1 1,2 CCE
I am trying query like below
select * from XYZ where ProgramID in('1')
No result is coming from above query, my question is single value matching with in query. I dont want like query match with exact value
Upvotes: 0
Views: 55
Reputation: 1269753
You have a broken data model. You can do what you want using LIKE
:
select *
from XYZ
where ',' + ProgramID + ',' like '%,1,%';
That said, you should understand why storing multiple values in a string is wrong:
Upvotes: 2
Reputation: 21
You can use:
Select * from XYZ WHERE (',' + Rtrim(ProgramID) + ',') LIKE '%,1,%'
Use TRIM
to eliminate any Spaces at the start and end of the string.
Upvotes: 2