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!

Trouble using SQL insert with declared variables

Status
Not open for further replies.

mhenley

IS-IT--Management
Aug 25, 2000
27
US
I'm writing an ASP page using VBScript to insert data into a SQL table. After I execute the string I'm getting the error Incorrect syntax near ')'. The code where I declare the query string is as follows:

'------------------------------------------------------------------------
InsSicLog = "Insert leads (siclogin) values ("&SicCounter&")"
'------------------------------------------------------------------------

where siclogin is the column name in leads table and SicCounter is a variable defined earlier in the code.


I know this is just a syntax problem, but I can't figure out what I am doing wrong. Any help would be greatly appreciated. Thanks!
 
seems to me you'd need to tell it which table to insert into.

Insert leads(siclogin) into mytable.....
 
Leads is the name of the table, and siclogin is the name of the column. The basic format is:

INSERT <tablename> (<columnname>) VALUES (<value>)

If I don't use variables (i.e. &SicCounter&) it works fine. I think I am just formating the variable in the query string wrong.
 
Does this work?

&quot;Insert leads (siclogin) values ('&quot; & SicCounter & &quot;')&quot;
 
That did it! Wierd though, I thought the apostrophe was only to be used for String identifiers. My field SicLogin was defined as integer in the SQL DB. I guess VBScript would rather go out and find for itself what the data type is.

Thanks for your help Nick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top