query help

  • example

    columns names a ,b c, d

    a b c d

    1 5 5 =10

    2 4 10 = 14

    3 8 14 = 22

    i want to write a query so that i can get calc like this with out using cursor

  • saby (7/24/2009)


    example

    columns names a ,b c, d

    a b c d

    1 5 5 =10

    2 4 10 = 14

    3 8 14 = 22

    i want to write a query so that i can get calc like this with out using cursor

    Okay, you are correct, you shouldn't need a cursor. Please read the first article I have referenced below in my signature block regarding asking for assistance. Follow the instructions in that article on what you need to post and how to post it to get the best help in response to your post.

    Also, please be sure to post the code you have also written so we may see what you have attempted to write to solve your own problem as well.

  • Hi,

    Is this the solution you are looking for

    Create table sam(

    a int,

    b int,

    c int,

    d int)

    go

    insert into sam(a,b,c) values(1,5,5)

    go

    insert into sam(a,b,c) values(2,4,10)

    go

    insert into sam(a,b,c) values(3,8,14)

    go

    Update sam

    Set d = (b+c)

    from sam x,

    (Select a,(b+c) as d from sam) y

    where x.a=y.a

    Select * from sam

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

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