Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002
    Location
    mumbai,india
    Posts
    7

    Unanswered: Unique Update Requirement

    How to get this ?

    update xxx set
    a=a+1 where x =1 ,
    a =a+1 where x=2.

    is it possible ???


    nilesh shah

  2. #2
    Join Date
    Feb 2002
    Location
    mumbai,india
    Posts
    7

    typo mistake

    it's me, nilesh again

    ignore above Q.

    reply to this Question :

    update xxx set
    a = a + 1 where x = 1
    a = a - 1 where x = 2


    sorry for typo mistake.

  3. #3
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    Run this
    --------------------------------------------------------------------------------------------------
    create table #tmp(a int, x int)

    insert into #tmp values(1,0)
    insert into #tmp values(1,1)
    insert into #tmp values(1,2)
    insert into #tmp values(1,3)

    select * from #tmp
    update #tmp set a = case x when 1 then a + 1 when 2 then a - 1 else a end
    select * from #tmp

    Should produce this
    --------------------------------------------------------------------------------------------
    a x
    ---- ----
    1 0
    1 1
    1 2
    1 3

    a x
    ---- ----
    1 0
    2 1
    0 2
    1 3
    --------------------------------------------------------------------------------------------
    Paul Young
    (Knowledge is power! Get some!)

Posting Permissions

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