Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Varioable in SQL statement

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Varioable in SQL statement

On Nov 11, 10:39*am, JimBob wrote:
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?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Varioable in SQL statement

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

"UglyChicken" wrote:

On Nov 11, 10:39 am, JimBob wrote:
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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Varioable in SQL statement

On Nov 11, 11:06*am, JimBob wrote:
Thanks UglyChicken - Not for Access, *this is for SQL Server. *I tried your
suggestions and got same error message - "invalid column name"



"UglyChicken" wrote:
On Nov 11, 10:39 am, JimBob wrote:
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?- Hide quoted text -


- 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Varioable in SQL statement

Luv the UglyChicken - single quote worked great !

"UglyChicken" wrote:

On Nov 11, 11:06 am, JimBob wrote:
Thanks UglyChicken - Not for Access, this is for SQL Server. I tried your
suggestions and got same error message - "invalid column name"



"UglyChicken" wrote:
On Nov 11, 10:39 am, JimBob wrote:
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?- Hide quoted text -


- 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
Can an If statement answer an If statement? M.A.Tyler Excel Discussion (Misc queries) 2 June 24th 07 04:14 AM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM


All times are GMT +1. The time now is 11:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"