Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

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]Incorrect syntax near ','.  
 
The error occurred in C:\inetpub\wwwroot\project2\admin\com\insert.cfc: line 302
 
300 :     (prodID,catID)
301 :     VALUES
302 :     <cfloop from="1" to="#listlen(arguments.structform.category)#" index="x">
303 :     (#NewProductID#, #listgetat(arguments.structform.category, x)#)
304 :     <cfif x lt listlen(arguments.structform.category)>,</cfif>
 

<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>

Open in new window

Avatar of gdemaria
gdemaria
Flag of United States of America image

Have you looked at the debug output to see what your query looks like when it's being run?

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?
oops, missed the comma, it looks like this..

      INSERT INTO ProductCategories (prodID,catID)
      VALUES (1, 21), (1, 25), (1, 30), (1, 36)

ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Coast Line

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