SQL WHERE clause help

jopu

New member
Local time
Today, 07:27
Joined
Nov 6, 2007
Messages
2
Hi all!

I'm trying to find a way how can I use a list (which I have currently stored in a table) in a SQL WHERE clause.

What I mean is that I have this SQL clause which sets a check box if town name matches any of the 3 town names in the clause...

Code:
SQL2 = "UPDATE tblImport SET Local = -1 WHERE Town = 'VANTAA'
OR Town = 'HELSINKI' OR Town = 'ESPOO';"

My question is how could I change the "static" town names in the clause to variable with the town names from a list I have stored in a table (table is just list of towns nothing else).

Would highly appreciate if anyone would be able to help me :)

Thanks a lot
Joni
 
Try

...WHERE Town IN (SELECT Town FROM OtherTable)
 
Something like below should work when you add your table and field name


sql2 = "UPDATE tblImport inner join [Your Table Name] On tblImport.Town=[Your Table Name].[FieldName] SET Local = -1 "
 
Thanks KeithG!

"SQL2 = "UPDATE tblImport inner join tblPeipponen On tblImport.Town=tblPeipponen.Town SET Peipponen = -1;"

Works :D

pbaldy: I had try that one earlier but returned an input box for "Town".

I'm still in baby shoes when it comes to all bits and pieces of SQL clauses... learning more every day though!

Thanks again!
Joni
 
glad I could help. Pbaldy's way should have worked also.
 
Mine would have worked, but I'd guess the join method is more efficient anyway.
 

Users who are viewing this thread

Back
Top Bottom