SQL Select Where the variable contains a singular value in string

panhead802
panhead802 used Ask the Experts™
on
I need to create a simple sql select statement that will allow to select all of the records in a talbe that have the same ID tag that appear in a string value:

I have a variable value of 'ASD' the field in the table WIP_ID is a single character and I need to be able to return the results only if the single character is in the string variable.

This needs to be in one select as that number of ID's in the variable field will based on user input.

I am at a loss.

Any help would be great.
THanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Is this what you're after?

SELECT
   *
FROM
   YourTable
WHERE
   CHARINDEX(WIP_ID,@YourVariable) <> 0

Author

Commented:
Thanks so Much, it works perfectly.
Top Expert 2010

Commented:
If your variable value is 'ASD', or you need to return records where in (A,S,D)...

SELECT *
FROM SomeTable
WHERE PATINDEX('[' + @YourVariable + ']', WIP_ID) > 0

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial