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 |
|
joriveek
Starting Member
33 Posts |
Posted - 2006-04-11 : 04:07:43
|
| Hi,Let me rephase my question on SQL Update:I want to perform Update on TOP(1) only result set has more than one row yielded after matching search criteria(in WHERE cluase).I want to perform Update on All the rows in a result set in case of distinct rows.At the moment, if I use TOP(1), Update performs on the Top(1) all the times, irrespective of the result set is unique or not.I want two are done in a single UPDATE |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-11 : 04:13:16
|
| Post some sample data and the result you wantMadhivananFailing to plan is Planning to fail |
 |
|
|
joriveek
Starting Member
33 Posts |
Posted - 2006-04-11 : 04:36:12
|
| Case 1:Description Value Flag--------------------------Item_1 300Item_1 300I need to set the Flag to 0 for TOP(1) row only, because data is same here and ignore the second recordCase 2)Description Value Flag--------------------------Item_1 300Item_1 600In this case I need to set the Flag to 0 for both rows,I want one single Update Statement to cater the both of the above cases |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-11 : 04:58:12
|
| Thats why you need to have unique column to avoid duplicatesWhy do you want to do this?Give more details on what you are trying to doMadhivananFailing to plan is Planning to fail |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2006-04-11 : 04:59:06
|
You could try try something like this:SELECT Description, ValueFROM TableNameGROUP BY Description, ValueIF @@ROWCOUNT > 1BEGIN SET ROWCOUNT 1 -- Do Update SET ROWCOUNT 0ENDELSEBEGIN -- Do UpdateEND Depending on your exact situation you might want to select a count into a local variable and test that rather than @@ROWCOUNT.-Lamprey |
 |
|
|
|
|
|