Solved

rown number Delete

Posted on 2011-09-09
6
291 Views
Last Modified: 2012-05-12

What is wrong with my delete

getting this error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'sp'.

Delete from (
Select *,
Row_NUmber() over (partition by EmailAddress order by CreationTime Desc) rn 
from OpenClickThru where EmailAddress is Not NULL
) sp
Where sp.rn > 1 ;

Open in new window

0
Comment
Question by:Leo Torres
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 250 total points
ID: 36514248
Try this:


;with cte as
(
Select *, Row_NUmber() over (partition by EmailAddress order by CreationTime Desc) rn
from OpenClickThru)
delete from cte
where EmailAddress is Not NULL and rn >1
0
 
LVL 22

Assisted Solution

by:Thomasian
Thomasian earned 250 total points
ID: 36515011
To correct the syntax of your query:
Delete sp
FROM (Select *,
			Row_NUmber() over (partition by EmailAddress order by CreationTime Desc) rn 
		from OpenClickThru where EmailAddress is Not NULL
	) sp
Where sp.rn > 1 

Open in new window

0
 
LVL 8

Author Comment

by:Leo Torres
ID: 36515532
dqmq: yours worked fine

But I am still curious because I would like to know why
Thomasian: did not work this was what I was tring to do there must be a way to do this with out CTE right?

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'Select'.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ')'.
0
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 
LVL 22

Expert Comment

by:Thomasian
ID: 36515537
Did you run the query as is? Maybe you left out the word "FROM" since I get the same error without it.
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 36515687
Ha that's what it was..

Thanks
0
 
LVL 42

Expert Comment

by:dqmq
ID: 36516472
Original query not missing "FROM", missing "SP" before the "FROM". :>)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question