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
 General SQL Server Forums
 New to SQL Server Programming
 delete statement

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2012-01-19 : 10:57:36
Hi, what is wrong with this? Thank you

delete * from
(
select periodKey,JobKey,BUKey,LedgerKey,COUNT(*) from Audit_JobNC
group by periodKey,JobKey,BUKey,LedgerKey
having 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.
Go to Top of Page

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.
Go to Top of Page

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 6
Incorrect syntax near ')'.

How should I re-word my query? Thank you
Go to Top of Page

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.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 11:19:10
there is no DELETE * in SQL Server

Did they EVER change that in M$ Access



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

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 BY

are 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 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -