simple select statement.. help

  • Hi friends,

    I have a problem selecting or finding from a database. It is given as below:

    I have a name column (varchar(20)) which contains John, Jojo, Johan, Mania etc.

    Suppose I want to select all those names which contains substring, say "Jo".

    And one more thing, how will I update all those columns containing "Jo" substrings with another substring; say "Lo"?

    Please help me, i'm a beginner in MS SQL Server

    Thanks in advance

    Chhana

  • Take a look at REPLACE in BOL.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Ooh, and as for "How to SELECT", have a look at LIKE.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Just to illustrate Frank's methods..

    declare @string varchar(50)
    set @string = 'Frank and John are back'
    
    if charindex('Jo', @string) > 1
      print 'exists'
    else
      print 'not exists'
    /***********************/
    select * from myTable where myCol like 'Jo%'
    /***********************/
    update myTable
    set myCol = case 
            when myCol like 'Jo%' then replace(myCol, 'Jo', 'Lo')
            else myCol
                end
    







    **ASCII stupid question, get a stupid ANSI !!!**

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply