SQL Challenge Update, Inner Join, Set, Where

Steve400

Registered User.
Local time
Today, 13:22
Joined
May 1, 2013
Messages
33
I have a form with a checkbox. If the box is checked I want a table updated.
I have the below query, which works but I want to add a where clause and cant figure out where it fits it. Can someone please help with structure.

Private Sub RCSSub_AfterUpdate()
Dim dbs As Database
Dim qdf As QueryDef
Set dbs = CurrentDb()

If Me.RCSSub = "-1" Then _
dbs.Execute "Update (T1 inner join T2 on T1.Key = T2.Key) left join T3 on T1.key=T3.key " _
& "Set PrintLabel = ""-1"" ;"

Me.Requery

dbs.Close

End Sub


The where statement I want to add is:
"where T3.Key is null"

When in this should return all records from T1 that are also in T2 but not in T3.

thanks
 
I would build and test the query in the design grid. Then copy the SQL from there.
 
I would build and test the query in the design grid. Then copy the SQL from there.

Can you write update SQLs in the design grid view?

I got around this issue by adding a 2nd update SQL but it would still be good to now how to structure an UPDATE, INNER JOIN, SET SQK with a WHERE statement.


If Me.RCSSub = "-1" Then _
dbs.Execute "Update (T1 inner join T2 on T1.Key = T2.Key " _
& "Set PrintLabel = ""-1"" ;"

dbs.Execute "Update T1 inner join T3 on T1.Key = T3.Key "
& "Set PrintLabel = ""0"" ;"
 
try this:
dbs.Execute "Update T1 Set PrintLabel = '-1' " _
& "FROM T1 inner join T2 on T1.Key = T2.Key " _
& "left join T3 on T1.key=T3.key " _
& "WHERE T3.Key Is Null"

David
 

Users who are viewing this thread

Back
Top Bottom