tags:

views:

262

answers:

1

Hi,

Say I have this table schema.

ID AccNo Amount

Say I have this data

ID     AccNo    Amount
1      1020     100.00
2      2040     50.00

How do I write a TSQL update query to update AccNo 1020 amount column with the amount from 2040??

Malcolm

+4  A: 

Use a nested select:

UPDATE tablename SET Amount = (
    SELECT Amount FROM tablename WHERE ID = 2 )
WHERE AccNo = 1200

Obviously if your condition is different, you'll have to tweak to suit, e.g. if AccNo is unique, you can use that.

Jeremy Smyth
Acually I want to add the amount on to the amount not just update it???
Malcolm
And also what if there is a CustNo column and that has to be included in the where clauses so the they match?? Sorry forgot about these points.
Malcolm