JohnMac328
asked on
CF -Incorrect syntax near '@P1'.
I am using a form with a insert query - I did a form dump and all the values are correct - for some reason I keep getting the Incorrect syntax near '@P1'. which does not google many answers.
Thanks
SQLServer JDBC Driver][SQLServer]Incorrec t syntax near '@P1'.
The error occurred in C:\inetpub\wwwroot\maxibil lion_CF\Bu y_Prize.cf m: line 53
51 : <cfqueryparam value="#form.gift_present1 5#" cfsqltype="cf_sql_varchar" > ,
52 : <cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer" > ,
53 : <cfqueryparam value="#form.gift_presentc olor#" cfsqltype="cf_sql_varchar" >
54 : )
55 : </cfquery>
<cfif structKeyExists(FORM, "submitButton15")>
<cfquery name="entershirts" datasource="IntranetDB_Col dfusion">
INSERT INTO prize_records (purchaser, award_desc, award_cost, award_color)
(
<cfqueryparam value="#form.employeeID#" cfsqltype="cf_sql_integer" > ,
<cfqueryparam value="#form.gift_present1 5#" cfsqltype="cf_sql_varchar" > ,
<cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer" > ,
<cfqueryparam value="#form.gift_presentc olor#" cfsqltype="cf_sql_varchar" >
)
</cfquery>
</cfif>
Thanks
SQLServer JDBC Driver][SQLServer]Incorrec
The error occurred in C:\inetpub\wwwroot\maxibil
51 : <cfqueryparam value="#form.gift_present1
52 : <cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer"
53 : <cfqueryparam value="#form.gift_presentc
54 : )
55 : </cfquery>
<cfif structKeyExists(FORM, "submitButton15")>
<cfquery name="entershirts" datasource="IntranetDB_Col
INSERT INTO prize_records (purchaser, award_desc, award_cost, award_color)
(
<cfqueryparam value="#form.employeeID#" cfsqltype="cf_sql_integer"
<cfqueryparam value="#form.gift_present1
<cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer"
<cfqueryparam value="#form.gift_presentc
)
</cfquery>
</cfif>
ASKER
No idea where @P1 is coming from - made the change and it gives
SQLServer JDBC Driver]Invalid parameter binding(s).
The error occurred in C:\inetpub\wwwroot\maxibil lion_CF\Bu y_Prize.cf m: line 53
51 : <cfqueryparam value="#form.gift_present1 5#" cfsqltype="cf_sql_varchar" > ,
52 : <cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer" > ,
53 : '<cfqueryparam value="#form.gift_presentc olor#" cfsqltype="cf_sql_varchar" >'
The fields and data match up
SQLServer JDBC Driver]Invalid parameter binding(s).
The error occurred in C:\inetpub\wwwroot\maxibil
51 : <cfqueryparam value="#form.gift_present1
52 : <cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer"
53 : '<cfqueryparam value="#form.gift_presentc
The fields and data match up
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I put the quotes around the varchar types and it is back to parameter binding error
Invalid parameter binding(s).
The error occurred in C:\inetpub\wwwroot\maxibil lion_CF\Bu y_Prize.cf m: line 53
51 : '<cfqueryparam value="#form.gift_present1 5#" cfsqltype="cf_sql_varchar" >' ,
52 : <cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer" > ,
53 : '<cfqueryparam value="#form.gift_presentc olor#" cfsqltype="cf_sql_varchar" >'
Invalid parameter binding(s).
The error occurred in C:\inetpub\wwwroot\maxibil
51 : '<cfqueryparam value="#form.gift_present1
52 : <cfqueryparam value="#form.value15#" cfsqltype="cf_sql_integer"
53 : '<cfqueryparam value="#form.gift_presentc
ASKER
I was missing the word VALUES
You couldn't figure that out from "Incorrect syntax near '@P1'."? It so completely obvious. I knew it the moment I saw it .. (not) ;-) That has to be the most cryptic/misleading error message I've seen all day, lol. Glad you figured it out.
ASKER
LOL - thanks agx - what got me was that there is nothing out there that explains it when you google the problem
Yeah, there wouldn't be. Due to the cfqueryparam's the actual values are translated into @P1, @P2, ... nonsense in jdbc (where the "1" is the first parameter, etc...).
Unfortunately the real error (without the params) isn't much better ;-) In MS SQL this:
INSERT INTO someTable ( 1 )
Gives the wonderfully informative error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '1'.
Ye-ah, incorrect syntax could be one of a hundred things. Could you narrow it down a little? At least the "near" part is accurate. You eventually figure those kinds of errors out. But it would be nice to see something a little more direct like "missing VALUES keyword" maybe? ;-)
Unfortunately the real error (without the params) isn't much better ;-) In MS SQL this:
INSERT INTO someTable ( 1 )
Gives the wonderfully informative error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '1'.
Ye-ah, incorrect syntax could be one of a hundred things. Could you narrow it down a little? At least the "near" part is accurate. You eventually figure those kinds of errors out. But it would be nice to see something a little more direct like "missing VALUES keyword" maybe? ;-)
ASKER
At least now I know the first thing to look for when I see that one :)
If your cfqueryparam contains a string value, it has to be enclosed in single quotes, if it a numeric value, then it does not.
You should add single quotes.
'<cfqueryparam value="#form.gift_presentc