Avatar of panhead802
 asked on

SQL Select Where the variable contains a singular value in string

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.
Microsoft SQL Server 2005Microsoft SQL Server

Avatar of undefined
Last Comment
Patrick Matthews

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks so Much, it works perfectly.
Patrick Matthews

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

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

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck