Upgrade Script needed

  • Hi All

        I have table already populated with some data. These are some changes in Flags setting in UI and this is to be incorporated in database. Table has 3 Flag columns Recreate, Update and Append. I need to update this table with logic :

    case  When Recreate_Flag = T then Update_Flag=T and Append_Flag=T

             Else  Inverse(Update_Flag) & inverse(Append_Flag).

    All the Flags are BIT. 

     

    Before

    : Recreate Update Append

                   T         F           F

                   F         F           T

                   F         T           T

    After

    : running script

    Recreate

    Update Append

           T       T         T

            F      T          F

            F      F          F

     

    i really don't want use cursor in this operations , Is there any built in function that could inverse the values ??

     

     

                      

                     

                 

     

     

     

      

     

    Regards
    Shrikant Kulkarni

  • Of course, you could combine these 2 updates into one using a more complex case statement, but this should get you heading in the right direction.

    declare @t table (Recreate_flag bit, Update_flag bit, Append_flag bit)

    insert into @t

    select 1,0,0 union all select 0,0,1 union all select 0,1,1

    select * from @t

    update @t

    set update_flag = 1, append_flag = 1

    from @t

    where recreate_flag = 1

    select * from @t

    update @t

    set update_flag = (case update_flag when 0 then 1 else 0 end), append_flag = (case append_flag when 0 then 1 else 0 end)

    from @t

    where recreate_flag = 0

    select * from @t

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Hi

     Thanks for the reply.. I found more simpler one

    declare @t table (Recreate_flag bit, Update_flag bit, Append_flag bit)

    insert into @t

    select 1,0,0 union all select 0,0,1 union all select 0,1,1

    select * from @t

    update @t

    set update_flag = case recreate_flag when 1 then 1 else ~(update_flag)end ,

        append_flag = case recreate_flag when 1 then 1 else ~(append_flag) end

    from @t

    select * from @t

    i guess, this works..  

     

    Regards
    Shrikant Kulkarni

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

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