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 |
Cornelius19
Starting Member
30 Posts |
Posted - 2008-11-11 : 18:45:04
|
Hi,I have a table with two columns: prod and sel. The prod column contains numeric values and is not null. I would like to update the sel column of the 1000 records with the highest prod value. I tried the following but got an "incorrect syntax" error message:UPDATE MyTableSET TOP 1000 sel = 1 ORDER BY prod DESCDo you have any suggestions how to do this?Cornelius |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
cvraghu
Posting Yak Master
187 Posts |
Posted - 2008-11-12 : 00:37:16
|
quote: Originally posted by tkizer UPDATE MyTableSET sel = 1 FROM (SELECT TOP 1000 sel FROM MyTable ORDER BY prod DESC) t
Shouldn't we have where clause in this query to connect the primary keys. Just curious. I don't have SQL server to test it out. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-12 : 00:41:55
|
[code]UPDATE MyTableSET sel = (SELECT MAX(prod) FROM MyTable) WHERE prod IN (SELECT TOP 1000 prod FROM MyTable ORDER BY prod)[/code] |
 |
|
Cornelius19
Starting Member
30 Posts |
Posted - 2008-11-12 : 12:34:00
|
Great! Thanks a lot! |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-12 : 12:39:59
|
Welcome |
 |
|
|
|
|