Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 127431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:28:32+00:00 2026-05-11T05:28:32+00:00

What is wrong with the statement below? I keep getting the following error message….

  • 0

What is wrong with the statement below? I keep getting the following error message…. Server: Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword ‘THEN’.

update oildatasetstatus set oildatasetstatusid =      case      WHEN 5 THEN 16             WHEN 6 THEN 17             WHEN 7 THEN 18             WHEN 8 THEN 18             WHEN 9 THEN 18             WHEN 10 THEN 19             WHEN 11 THEN 20         End where oildatasetlabstatusid in  (                 select oildatasetstatusid                 from OilDataSetStatus                 inner join OilDataSet on OilDataSet.OilDataSetID =                      OilDataSetStatus.OilDataSetID                 where SamplePointID in                  (                                 select SamplePointID                                  from SamplePoint                                 where CustomerSiteID in                                 (                                                 select CustomerSiteID                                                 from CustomerSite                                                 where CustomerID = 2                                 )                 ) ) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:28:32+00:00Added an answer on May 11, 2026 at 5:28 am

    The way you have your statement coded now will work (once you add the column reference to the case statement, as mentioned by other posts), however, to let the rest of your syntax go uncommented on would be a disservice to others in your situation.

    While you may only need to run this query once, I and others have run into similar situations where an Update to multiple rows also relies on data 3 or 4 tables away from our source and has to be run many times (like in a report).

    By collapsing your sub selects into a single select statement and saving the results of that into a #Temp table or a @Table variable, you only have to do that lookup once, then select from the result set for your update.

    Here is a sample using a @table variable:

    declare @OilStatus table (oilDatasetStatusID int) insert into @OilStatus     select odss.oildatasetstatusid     from OildataSetStatus odss     join oilDataSet ods on ods.OilDataSetID = odss.OilDataSetID     join SamplePoint sp on sp.SamplePointID = odss.SamplePointID     join CustomerSite cs on cs.CustomerSiteID = sp.CustomerSiteID     where cs.CustomerID = 2  update oildatasetstatus set oildatasetstatusid =      case oildatasetstatusid         WHEN 5 THEN 16                 WHEN 6 THEN 17                 WHEN 7 THEN 18                 WHEN 8 THEN 18                 WHEN 9 THEN 18                 WHEN 10 THEN 19                 WHEN 11 THEN 20     end where oildatasetlabstatusid in ( select oilDatasetStatusID from @OilStatus ) 

    Since I do not have your exact schema, there may be errors when trying to implement the sample above but I think you will get the idea.

    Also, whenever multiple tables are used in a single statement try to preface every column name with an alias or the full table name. It helps keep both the sql engine and the people reading your code from getting lost.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to run the following statement, an error message is returned: Server:
What is wrong with this statement? I`m having the following error: Error 10 'System.Web.Mvc.HtmlHelper'
Can you figure out what is wrong with the statement below? GCC error states:
Update - I fixed the query below. I had the wrong query/error statement :(
Can you please point out what I am doing wrong in following statement? $db
I would like to know if there is anything wrong with the below statement.
I don't know what is wrong with the below code.... I am getting input
What is Wrong with this statement It is showing syntax error <%= link_to image_tag('cancel.png'),
Problem Statement:- In my below code, I am getting list of User's which I
The IF statement below causes a 500 error. The page loads fine when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.