Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a different type of SQL variable question 1

Status
Not open for further replies.

EddieVenus

Technical User
Apr 8, 2002
176
US
I can make SQL querys that use variable at the end of the query string.
I.E. "SELECT Location FROM t_CustInfo WHERE CompanyName = '" & compname & "'"
But I am having trouble putting the varible into the sting in the middle. What I am trying to do is to have a variable that stands for DISTINCT so that the user has the option to find all the records or just the unique ones. I have this code for it, since it is the logical adoption of the code used to input variables at the end.
"SELECT '" & u & "'CIDresponse FROM t_CircuitID"
in this case u is just a check box, either DISTINCT or null, and if I do this string without the variable I do get the proper records back wether I use DISTINCT or not. Please tell me what I am doing wrong, I have tried many variations of the string and none have worked. Thank you.
 
Because you are inserting a SQL construct instead of a value, you don't need to use single quotes:

"SELECT " & u & " CIDresponse FROM t_CircuitID"

Also, make sure that your spacing is right. After building your string, write it to the screen... if it looks right, copy it and run it in your database to see if it works there.


 
Excellent, it works like a charm. I actuallty tried this useage of quotes at one point and it did not work becasuse I was misspelling DISTINCT the whole time. But if it weren't for you JuanitaC, I could have gone on all day or more without knowing the answer. Thank you for your assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top