Select in SQL

Posted on 2012-09-12
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

    select * from myTable where idlist like '%,417,%' or idlist like '417,%' or idlist like '%,417' or idlist ='417'

    Author Closing Comment

    Thanks. It works.
    LVL 22

    Expert Comment

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now