How to use between clause in the case statement?

Mangesh12145 6 Reputation points
2023-03-21T04:34:03.0866667+00:00

Hello Team,

I am unable to use the below case statement in the where clause. It is saying, incorrect token between. Please see and suggest:

Where [TWPP] = case when [Company]='ABC INC.' then [TWPP] between 91 And 92 else [TWPP] between 89 And 100 end as "TWPP"

and [RNGG] = case when [Company]='ABC INC.' then [RNGG] between 8 And 12 else [RNGG] between 4 And 14 end as "RNGG"

Please help.

SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. Mangesh12145 6 Reputation points
    2023-03-21T09:44:50.6233333+00:00

    I got my answer. I did create 2 CTE and applied case statements while fetching data in the select query.

    Thank you all.

    1 person found this answer helpful.
    0 comments No comments

  2. Olaf Helper 47,436 Reputation points
    2023-03-21T07:09:23.8366667+00:00

    Hello Team

    No team; this is a community forum with volunteers.

    then [TWP] between 91 And 92

    Then Between? What for a result do you expect here?

    Please describe in clear wods what you are trying to achieve here.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.