Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
delpiero
Yak Posting Veteran
98 Posts |
Posted - 2005-05-18 : 22:49:56
|
| I have a rather stupid question, but as I am dealing with some critical data I really hope someone can confirm me this ...One row in a table called invoices, all fields are stringsNumber1 Number2 invoice_number123 456 123456A simple update statement ..declare @a1 char(3)declare @a2 char(3)set @a1='ABC'set @a2='DEF'UPDATE invoices set Number1=@a1, Number2 = @a2, invoice_number = number1 + number2 where invoice_number = '123456'After this UPDATE statement, Number 1 becomes 'ABC' and Number2 becomes 'DEF' as expected. For invoice_number, the new value is '123456' instead of 'ABCDEF', meaning that it used the old value of Number1 and Number2 to calculate invoice_number. Is that we must use invoice_number = @a1 + @a2 and cannot use @number1 + @number2 (which is how the value invoice_number is actually defined)? Thanks,delpiero |
|
|
Ex
Posting Yak Master
166 Posts |
Posted - 2005-05-18 : 23:46:42
|
| yeh the value cant be updated like that when performing an update the new values aren't set one at a time. the new values appear to be set all at once ( not exactly sure if this is technically correct but it in practice this is what appears to happen)so you would need to set invoice_number = @a1+ @a2which will work out how you wanted it.UPDATE invoicesset Number1=@a1,Number2 = @a2,invoice_number = @a1+ @a2where invoice_number = '123456'only way to do it :)------------------------------------------------------------------Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Rich Cook |
 |
|
|
|
|
|
|
|