Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here am trying to run the below said delete subquery to delete some records in table1.But am getting syntax error while running.

Can you assist me on this?

What I have tried:

Do.Cmd.RunSQL “Select count(*) from table1 where id in (select id from table 2 where ENVRNMNT_STATUS = "Prod" and RELEASE_FLAG= "N")
Posted
Updated 8-Apr-18 22:07pm
Comments
GJSS 5-Apr-18 11:42am    
Do.Cmd.RunSQL “delete * from table1 where id in (select id from table 2 where ENVRNMNT_STATUS = "Prod" and RELEASE_FLAG= "N")

Try changing it to
SQL
Do.Cmd.RunSQL "delete * from table1 where id in (select id from [table 2] where ENVRNMNT_STATUS = 'Prod' and RELEASE_FLAG= 'N')"

Unless that table is not called table 2 but is table2 in which case use
SQL
do.Cmd.RunSQL "delete * from table1 where id in (select id from table2 where ENVRNMNT_STATUS = 'Prod' and RELEASE_FLAG= 'N')"

Note the use of single-quotes in both cases
 
Share this answer
 
v3
Comments
GJSS 5-Apr-18 17:03pm    
I tried with this query
DoCmd.RunSQL “Delete * from table1 where id in (select id from table2 where ENVRNMNT_STATUS = 'Prod' and RELEASE_FLAG= 'N')”

It didnt work it out
        
CHill60 5-Apr-18 18:49pm    
What do you mean "It didn't work it out"? You got an error? What?
GJSS 8-Apr-18 21:40pm    
Yes, it throws an error "end of statement" is valid with red highlighted color.
CHill60 9-Apr-18 3:54am    
Apologies - I put the close bracket in the wrong place - I've fixed the bug in my solution
Not an answer, but additional information to solution#1 by CHill60[^]...

MS Access very likes [;] at the end of query. On the other hand, you have to use transactions. I'd suggest to improve your query this way:
VB
DoCmd.RunSQL "delete * from table1 where id in (select id from table2 where ENVRNMNT_STATUS = 'Prod' and RELEASE_FLAG= 'N';);", True


See:
DoCmd.RunSQL Method (Access)[^]
SELECT Statement (Microsoft Access SQL) [Access 2007 Developer Reference][^]
Tips and Techniques for Queries in Access 2007[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900