[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Select in SQL

Posted on 2012-09-12
Medium Priority
Last Modified: 2012-09-12
Hi expert,

How can I select data if the column of my table contains "62,96,103,104,216,222,314,329,385,405,417,459,468,538,560,572,600,602".

I try:  select * from mytable where idlist like '%,417,%'
But it will fail if the id number 417 is at the first position.

Please help.
Question by:alexcryout
LVL 75

Accepted Solution

Aneesh Retnakaran earned 2000 total points
ID: 38392901
select * from myTable where idlist like '%,417,%' or idlist like '417,%' or idlist like '%,417' or idlist ='417'

Author Closing Comment

ID: 38392923
Thanks. It works.
LVL 22

Expert Comment

ID: 38393360
Another way to do this is to add comma at start and end of the list
select * from mytable where ',' + idlist + ',' like '%,417,%'

Open in new window


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question