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 |
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2012-01-19 : 10:57:36
|
| Hi, what is wrong with this? Thank youdelete * from (select periodKey,JobKey,BUKey,LedgerKey,COUNT(*) from Audit_JobNCgroup by periodKey,JobKey,BUKey,LedgerKeyhaving COUNT(*) >1) |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-19 : 10:59:21
|
what is wrong -> group by No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-19 : 11:00:26
|
Also is wrong NOT to tell the error message or whatever... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2012-01-19 : 11:03:53
|
| Sorry, the following is the error message:Msg 102, Level 15, State 1, Line 6Incorrect syntax near ')'.How should I re-word my query? Thank you |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-19 : 11:08:29
|
Just a guess:There are duplicates in your table.You want to delete the duplicates.The solution you have tried would delete ALL rows that have duplicates if it would work.Is that what you want?Or would you like to KEEP ONE row and delete the duplicates only? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-01-19 : 11:25:26
|
| you don't delete *, you just delete; so your query is malformed. However, I think you might be a little confused. What are you actually trying to do?It looks a little like you have found some duplications based on the GROUP BYare you sure you want to delete all of those? (so you'd end up with NO ROWS where before you had duplicates)Do you maybe instead want to be left with just one copy from each duplicate set. If you did then you need a slightly different query.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2012-01-19 : 11:41:11
|
| Hello tariq2,In addition to the others comments/questions, does [Audit_JobNC] have a primary or composite key which provides uniqueness?TIA. |
 |
|
|
|
|
|
|
|