Reputation: 77
So basically I have this column called Signature inserted in the database
Id = 1 Value = John, Micheal, Sara
Id = 2 Value = Mike, Steve, John . .
Now in asp.net I'm not sure how can I do select command and know if the value
John, Micheal, Sara
Has "Micheal" in it
Upvotes: 0
Views: 115
Reputation: 51494
No. Don't.
Add a new table with rows for each signature name, and use a row for each signatory. That is the point of relational databases.
1 John
1 Michael
1 Sara
2 Mike
2 Steve
2 John
Or better still, add two new tables - one for the signatories, and one for the relation between that and your initial table
Signatories
1 John
2 Michael
ItemSignatures
ItemID SignatoryID
1 1
1 2
2 1
Upvotes: 1
Reputation: 27322
To answer you question:
CHARINDEX() searches for a substring within a larger string, and returns the position of the match, or 0 if no match is found
SELECT * FROM [Table] WHERE CHARINDEX(Signature, 'Michael') > 0
Or
You can just use wildcards in the query (after IF, WHERE or ON):
SELECT * FROM [Table] WHERE Signature LIKE '%' + 'Michael' + '%'
But really you should be storing this data in a separate related table.
Upvotes: 1