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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Variable numbers in a SQL statement

Status
Not open for further replies.

tbiceps

IS-IT--Management
Nov 23, 2005
106
US
This is SQL statement that I'm using in my code. RptValue, and X represent variable that I want to alter. This SQL statement will not put the constant into the SQL string. If I try to do something similar to the following ('RptValue','X')" then I get the words not values. Does anyone have a clue.


SelClause = "INSERT INTO TBL_Index ([Report ID], [Field ID]) VALUES (RptValue,X)
 
If the values are coming off a form then you have to concat the values into the string.

SelClause = "INSERT INTO TBL_Index ([Report ID], [Field ID]) VALUES (" & RptValue & " ," & X & ")"

or use hiphens for a string

SelClause = "INSERT INTO TBL_Index ([Report ID], [Field ID]) VALUES ('RptValue','X')"
 
SelClause = "INSERT INTO TBL_Index ([Report ID], [Field ID]) VALUES [tt]('" & RptValue & "','" & X & "')"[/tt]

If [Report ID] or [Field ID] are defined as numeric in TBL_Index then get rid of the corresponding single quotes.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi, How about:

SelClause = "INSERT INTO TBL_Index ([Report ID], [Field ID]) VALUES ('" & RptValue & "' ,'" & X & "')"

Hope that helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top