Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need help with incorrect syntax error during a record update

Explorer ,
Oct 25, 2011 Oct 25, 2011

I'm getting the error below but I cannot figure out what I'm doing wrong.

Error Executing Database Query.

[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'WHERE'.

The error occurred in C:\ColdFusion9\wwwroot\Intranet\DM\Admin\Maintenance-BulbBaseType.cfm: line 23

21 :             UPDATE [Bulb Base Type Table]

22 :             SET [BulbBaseTypeDesc] = '#TxtBulbBaseTypeDesc#',

23 :             WHERE ([BulbBaseTypeID] = #TxtID#)

24 :         </cfquery>

25 :         <cfset TxtID = 0>

I have set my cfparam as:

<cfparam name="Submit" default="">

<cfparam name="TxtID" default=0>

<cfparam name="TxtBulbBaseTypeDesc" default="">

3.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Oct 25, 2011 Oct 25, 2011

Thanks. I'm new to ColdFusion and this is someone else's code. I appreciate the help.

Translate
Guide ,
Oct 25, 2011 Oct 25, 2011

Comma after your SET statement. Almost as if it's "near the keyword 'WHERE'"

AND WHERE ARE YOUR QUERYPARAMS?!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2011 Oct 25, 2011

A good rule of thumb when encountering this sort of error message is to examine the preceding line of code.

If you do that with your query, you should spot the trailing comma at the end of the line.

Also: read up on CFQUERYPARAM.  Don't hard-code dynamic values in your SQL string.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 25, 2011 Oct 25, 2011

Thanks. I'm new to ColdFusion and this is someone else's code. I appreciate the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2011 Oct 25, 2011
LATEST

In addition to the other answers, I find that leading commas are easier to work with than trailing commas.  Something like this:

update YourTable

set field1 = value1

, field2 = value2

, field3 = value3

etc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources