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

  • SEARCH
  • Home
  • 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 7892907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:59:07+00:00 2026-06-03T06:59:07+00:00

I am trying to run this simple query however it doesn’t even parse saying

  • 0

I am trying to run this simple query however it doesn’t even parse saying

Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword
‘between’.

Query is:

select  
    case DMProject.dbo.TypeFourTraining.Column2 
    when Column2 between 181 and 360 then '181-360' 
    when Column2 between 0 and 180 then '0-180' 
END as score 
from DMProject.dbo.TypeFourTraining 

The same doesn’t work for Column2 < 360 syntax neither..

I have searched over internet from msdn, and some other sites but I see that my syntax seems to be valid, then either there is a detail I need to know or there is something I can’t see 🙁

Can anyone please suggest a solution?

  • 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. Editorial Team
    Editorial Team
    2026-06-03T06:59:08+00:00Added an answer on June 3, 2026 at 6:59 am

    You cannot mix the simple and searched types of CASE expression. Remove the field name DMProject.dbo.TypeFourTraining.Column2 specified after the CASE.

    Correct syntax for your query:

    SELECT  CASE 
                WHEN Column2 between 181    AND 360 THEN '181-360' 
                WHEN Column2 between 0      AND 180 THEN '0-180' 
            END as score 
    FROM    DMProject.dbo.TypeFourTraining 
    

    Two types of CASE expressions:

    There are two types of CASE expression namely Simple and Searched. You cannot combine Simple and Searched in the same expression.

    Simple CASE:

    CASE input
        WHEN 1 THEN 'a'
        WHEN 2 THEN 'b'
        WHEN 3 THEN 'c'
        ELSE ''
    END
    

    Searched CASE with simple example:

    CASE 
        WHEN input = 1 THEN 'a'
        WHEN input = 2 THEN 'b'
        WHEN input = 3 THEN 'c'
        ELSE ''
    END
    

    Searched CASE with slightly complex example:

    This involves multiple columns. You can add multiple columns in each of the WHEN statements.

    CASE 
        WHEN input = 1 AND second_column = 2 THEN 'a'
        WHEN input = 2 AND third_column  = 3 THEN 'b'
        WHEN input = 3 AND (second_column = 4 OR third_column = 6) THEN 'c'
        ELSE ''
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run this simple SELECT query using PDO::MySQL, but it does
I'm trying to run this simple query over a JDBC connection: select _fk_DeptBillTo from
I am trying to run this dreadfully simple command in Bash java -cp nasa-top-secret.jar
I am trying to run this seemingly simple piece of code which is repeated
I'm trying to run this for loop; for (int col= 0; grid[0].length; col++) However
I'm trying to run a simple insert query to a database. I have it
This may seem like a simple question however i've spent the last hour trying
I am trying to run a simple FQL query: SELECT aid,name FROM album WHERE
I'm trying to run the following PHP script to do a simple database query:
I am trying to figure out the best way to run this query. 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.