Varioable in SQL statement

J

JimBob

All - I am trying to pass a variable to a SQL select statement using ADO data
connection, but keep getting error message back indicating "invalid column
name" - and it referw to teh VALUE of the variable I am passing.

A user selects a value from a drop down list in an Excel workbook (Cell
$C$1). I use that value to pass to to teh SQL query:

"Select * from Table1 where ClientName=" & range("C1").value

Any suggestions on how I maye be able to embed a variable into a SQL query?
 
U

UglyChicken

All - I am trying to pass a variable to a SQL select statement using ADO data
connection, but keep getting error message back indicating "invalid column
name" - and it referw to teh VALUE of the variable I am passing.

A user selects a value from a drop down list in an Excel workbook (Cell
$C$1).  I use that value to pass to  to teh SQL query:

"Select * from Table1 where ClientName=" &  range("C1").value

Any suggestions on how I maye be able to embed a variable into a SQL query?

You need to put quotes around the range value something like
"SELECT * FROM Table1 WHERE ClientName= " & Chr(34) &
range("C1").value & Chr(34) & ";"

This is for Microsoft Access?
 
J

JimBob

Thanks UglyChicken - Not for Access, this is for SQL Server. I tried your
suggestions and got same error message - "invalid column name"
 
U

UglyChicken

Thanks UglyChicken - Not for Access,  this is for SQL Server.  I tried your
suggestions and got same error message - "invalid column name"







- Show quoted text -

SQL server uses single quotes ie. Chr(39) replace the Chr(34) with it.
If you still have the same problem then double-check the spelling of
the field name ClientName and that it is definitely a field in table1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top