Want to modify the content of the cols

  • for example I have a table, which has ID, Service, Subservice cols.

    I want to modify or change 'Surgery Service' to 'XXX-Surgery' for the "Service" col where ID = 123,

    and from 'PEDI' to 'PEDI-SURGERY' for the "subservice" col where ID = 123

    Thanks

  • It seems like a simple update

     

     

    declare @t table (

    ID int, Service nvarchar(30), Subservice nvarchar(30))

     

    insert into @t

    select 123, 'Surgery Service', 'Test' union all

    select 123, 'Surgery Service', 'PEDI' union all

    select 123, 'Surgery', 'PEDI' union all

    select 124, 'Surgery Service', 'Pedi'

     

    select * from @t

     

    update @t

       set Service = case when Service = 'Surgery Service' then 'XXX-Surgery' else Service end,

           Subservice = Case when Subservice = 'Pedi' then 'PEDI-SURGERY' else Subservice end

      where ID = 123

     

    select * from @t 

     

     

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • hbanerje (4/17/2012)


    for example I have a table, which has ID, Service, Subservice cols.

    I want to modify or change 'Surgery Service' to 'XXX-Surgery' for the "Service" col where ID = 123,

    and from 'PEDI' to 'PEDI-SURGERY' for the "subservice" col where ID = 123

    Thanks

    Please provide the DDL (CREATE TABLE statement), sample data (series of INSERT INTO statements), expected output, and the code you have written so far to solve the problem.

  • hbanerje (4/17/2012)


    for example I have a table, which has ID, Service, Subservice cols.

    I want to modify or change 'Surgery Service' to 'XXX-Surgery' for the "Service" col where ID = 123,

    and from 'PEDI' to 'PEDI-SURGERY' for the "subservice" col where ID = 123

    Thanks

    Mike01 gave a good answer on this. My feeling is that you're pretty new to SQL and I'd like to help you learn a bit more about it. Do you know what "Books Online" is and how to get into it?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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