What is the easiest way to test if a target string 'ABC' is in the source string @sourceString?

Posted on 2007-10-02
Last Modified: 2010-03-19
What is the easiest way to test if a target string 'ABC' is in the source string @sourceString?

This is for SQL 2005
Question by:chuang4630
    LVL 39

    Accepted Solution


    if @sourceString like '%ABC%'
       select 'target exists in source'
       select 'target not exists in source'
    LVL 39

    Expert Comment

    if you want to use it in where clause of select/update/delete commands use it like

    select * from yourtablename
    where sourceColumn like '%ABC%'
    LVL 1

    Author Comment

    SQL gives me the error at this line

    if (@PONumber like '%-PF-%')

    LVL 1

    Author Comment

    I got it. Thanks

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    734 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

    17 Experts available now in Live!

    Get 1:1 Help Now