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 |
|
daniel50096230
Yak Posting Veteran
99 Posts |
Posted - 2011-12-12 : 21:30:12
|
| I need a loop to update the data. For example,Select Distinct Customer_ID FROM AThen For each customer_ID that selected, then updateUpdate A Set Status = 'A' Where Customer_ID = "Customer selected from the select statement"How can i write it? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-12 : 21:41:47
|
[code]update Aset Status = 'A'from A inner join( select Customer_ID from A group by Customer_ID having count(*) = 1) D on A.Customer_ID = D.Customer_ID[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-12 : 21:44:11
|
another way . .update Aset Status = 'A'from ( select Customer_ID, Status, cnt = count(*) over (partition by Customer_ID) from A) Awhere cnt = 1 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|