Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: SQL Query - Newbie

  1. #1
    Board Regular
    Join Date
    Aug 2010
    Posts
    331
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default SQL Query - Newbie

    Hi, (new to SQL) this may not be the best way to do this but does anyone know how I amend my code to NOT CONTAINS, currently this code searches for partial text anywhere in string, but I would like to adapt to partial text not anywhere in sting?

    Thank you

    Code:
    Code:
    --FREE LEGALS PRODUCT
    
    ,CASE
    
    WHENCHARINDEX('swi', mp.MGProductEligibilityGroupCode)> 0
    
    ORCHARINDEX('SAF', mp.MGProductEligibilityGroupCode)> 0
    
    ORCHARINDEX('L', mp.MortgageProductShortName)> 0
    
    Then'Y'
    
    ELSE'N'
    ENDAs'Free Legal Product'

  2. #2
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    74,110
    Post Thanks / Like
    Mentioned
    29 Post(s)
    Tagged
    2 Thread(s)

    Default Re: SQL Query - Newbie

    If the substring you are trying to find in the string isn't found, i.e. isn't contained within the string, then CHARINDEX will return 0.

    So you could have something like this.
    Code:
    WHEN CHARINDEX('swi', mp.MGProductEligibilityGroupCode) = 0 THEN 'N'
    If posting code please use code tags.

  3. #3
    Board Regular
    Join Date
    Aug 2010
    Posts
    331
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: SQL Query - Newbie

    Quote Originally Posted by Norie View Post
    If the substring you are trying to find in the string isn't found, i.e. isn't contained within the string, then CHARINDEX will return 0.

    So you could have something like this.
    Code:
    WHEN CHARINDEX('swi', mp.MGProductEligibilityGroupCode) = 0 THEN 'N'
    Thanks this didn't fully resolve it but help me re-order my code and get this to work, thank you

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •