Coast Line
asked on
getting mSSQL Err:
I have the following insert and doing insert in mSSQL:
getting error:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrec t syntax near ','.
The error occurred in C:\inetpub\wwwroot\project 2\admin\co m\insert.c fc: line 302
300 : (prodID,catID)
301 : VALUES
302 : <cfloop from="1" to="#listlen(arguments.str uctform.ca tegory)#" index="x">
303 : (#NewProductID#, #listgetat(arguments.struc tform.cate gory, x)#)
304 : <cfif x lt listlen(arguments.structfo rm.categor y)>,</cfif >
getting error:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrec
The error occurred in C:\inetpub\wwwroot\project
300 : (prodID,catID)
301 : VALUES
302 : <cfloop from="1" to="#listlen(arguments.str
303 : (#NewProductID#, #listgetat(arguments.struc
304 : <cfif x lt listlen(arguments.structfo
<cfquery datasource="#request.dsn#" name="myset" username="#request.user#" password="#request.pass#">
SET NOCOUNT ON
INSERT INTO products(productName, prodDesc, seller_ID, productaddon, status, prodShortDesc)
VALUES(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.structform.productname#" maxlength="255">,
<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#arguments.structform.productDesc#">,
<cfqueryparam cfsqltype="cf_sql_numeric" value="#arguments.structform.chooseSeller#">,
<cfqueryparam cfsqltype="cf_sql_timestamp" value="#CreateODBCDateTime(now())#">,
<cfqueryparam cfsqltype="cf_sql_numeric" value="#arguments.structform.status#">,
<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#arguments.structform.productShortDesc#">)
SET NOCOUNT OFF
select scope_identity() as productID;
</cfquery>
<cfset NewProductID = #myset.productID#>
<cfquery name="insertItemCats" datasource="#request.dsn#" username="#request.user#" password="#request.pass#">
INSERT INTO ProductCategories
(prodID,catID)
VALUES
<cfloop from="1" to="#listlen(arguments.structform.category)#" index="x">
(#NewProductID#, #listgetat(arguments.structform.category, x)#)
<cfif x lt listlen(arguments.structform.category)>,</cfif>
</cfloop>
</cfquery>
oops, missed the comma, it looks like this..
INSERT INTO ProductCategories (prodID,catID)
VALUES (1, 21), (1, 25), (1, 30), (1, 36)
INSERT INTO ProductCategories (prodID,catID)
VALUES (1, 21), (1, 25), (1, 30), (1, 36)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks This worked..
My Approach worked in Mysql but it failed in MSSQL Server..
Why So can u explain a bit on it
Regards
My Approach worked in Mysql but it failed in MSSQL Server..
Why So can u explain a bit on it
Regards
The way you have the loop, that will look like...
INSERT INTO ProductCategories (prodID,catID)
VALUES
(1, 21)
(1, 25)
(1, 30)
(1, 36)
Is that a valid SQL statment in your database?