Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help in the Delete Statement Expand / Collapse
Author
Message
Posted Wednesday, March 20, 2013 1:00 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 22, 2013 2:08 PM
Points: 19, Visits: 63
Hello all,
I need to delete a record that is duplicate between 2 tables.

The query looks like this:

Delete from request_form_table_testing as t1
where EXISTS
(select tEmail from request_form_temp_emails as t2
where t1.email = t2.tEmail)

but is giving me an error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.

I dont really know where is my syntax error.

Could you guys help me?

Thanks a lot
Post #1433431
Posted Wednesday, March 20, 2013 1:13 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:13 PM
Points: 13,085, Visits: 12,551
montse 22199 (3/20/2013)
Hello all,
I need to delete a record that is duplicate between 2 tables.

The query looks like this:

Delete from request_form_table_testing as t1
where EXISTS
(select tEmail from request_form_temp_emails as t2
where t1.email = t2.tEmail)

but is giving me an error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.

I dont really know where is my syntax error.

Could you guys help me?

Thanks a lot


You can't alias the table in your delete statement. You can do the same thing a number of different ways. Here are a couple of them.

Delete request_form_table_testing 
where tEmail in
(
select tEmail
from request_form_temp_emails as t2
join request_form_table_testing t1 on t1.email = t2.tEmail
)

delete request_form_table_testing
from request_form_table_testing as t1
where EXISTS
(select tEmail from request_form_temp_emails as t2
where t1.email = t2.tEmail)



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1433438
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse