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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 update just one row ?

Author  Topic 

mary_itohan
Posting Yak Master

191 Posts

Posted - 2008-10-09 : 11:25:50
Hello,
I have a table that could contain a few duplicate columns.

Whats the best way to update a column and set the value of only "ONE" row to an update status

ie



update history set Sent_Route = @each_recipient where batch = @transactionid and Receipient = @final_recipient


bear in mind the column receipient above could have duplicate values in a transaction.

Do i first do a select to get the top 1, PK value before the update or do i use @@rowcount to check to make sure only one value is updated ???



_____________________


Yes O !

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-09 : 12:03:01
you can just use

update top 1 history set Sent_Route = @each_recipient where batch = @transactionid and Receipient = @final_recipient
Go to Top of Page

mary_itohan
Posting Yak Master

191 Posts

Posted - 2008-10-09 : 13:22:31
No sir,

Msg 102, Level 15, State 1, Procedure S_billing, Line 435
Incorrect syntax near '1'.

_____________________


Yes O !
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-09 : 13:41:01
quote:
Originally posted by mary_itohan

No sir,

Msg 102, Level 15, State 1, Procedure S_billing, Line 435
Incorrect syntax near '1'.

_____________________


Yes O !


just missed a braces

update top (1) history set Sent_Route = @each_recipient where batch = @transactionid and Receipient = @final_recipient
Go to Top of Page

mary_itohan
Posting Yak Master

191 Posts

Posted - 2008-10-09 : 13:56:23
tnx

_____________________


Yes O !
Go to Top of Page
   

- Advertisement -