0

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

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0
select *
from Signature
where value like '%Micheal%'

1 Comment

When posting answers, please add and explanation describing what you changed or added or how it works or something. Even though your answer may be the solution, it's likely that some people who read this don't understand what it means or how it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.