Pass Variables in SQL WHERE clause
Pass Variables in SQL WHERE clause
(OP)
I need to be able to run a SQL query that will look something like this:
SELECT * FROM [TABLE] WHERE Field= (variable)
That is pass a variable to the WHERE clause.
assuming that I have a variable already present and that it holds the value of the a "field".
What is the CORRECT SYNTAX?
Any help will be great
Thanks
Alexis
SELECT * FROM [TABLE] WHERE Field= (variable)
That is pass a variable to the WHERE clause.
assuming that I have a variable already present and that it holds the value of the a "field".
What is the CORRECT SYNTAX?
Any help will be great
Thanks
Alexis
Alexis
alexisale@msn.com
RE: Pass Variables in SQL WHERE clause
Below is a sample code:
Dim strWhere as string
Dim strSQL as string
strWhere = text1.text 'Take in criteria from text box
strSQL = "SELECT * FROM [TABLE] WHERE Field="
strSQL = strSQL & strWhere
............
Obviuosly you need to open a connection to a database and bring back a recordset. If you are not sure how to do this let me know and I'll post the code.
HTH
C
RE: Pass Variables in SQL WHERE clause
For numeric fields:
"Select * From ..... Where myFld = " & NumericField
For string fields:
"Select * From ..... Where myFld = '" & StringField & "'"
where you're surrounding your data with single quotes.
For date fields (and Access):
"Select * From ..... Where myFld = #" & DateField & "#"
RE: Pass Variables in SQL WHERE clause
C