• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

TSQL SQL Server 2008

(select case ump.SIZE_OF_FIRM
 when (ump.SIZE_OF_FIRM >= 2 and ump.SIZE_OF_FIRM <= 5) then 4
 when (ump.SIZE_OF_FIRM between 6 and 10) then 3
 when (ump.SIZE_OF_FIRM between 11 and 25) then 2
 when (ump.SIZE_OF_FIRM > 25) then 1
end) as GroupTot,

The > throws an error
The "between" throws an error

How to set a value based on a range of a variable or constant
  • 3
  • 2
1 Solution
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
afaik since you're using multiple expressions, you'll have to lose the first ump.SIZE_OF_FIRM and declare the column within each WHEN line.
select case 
   when ump.SIZE_OF_FIRM >= 2 and ump.SIZE_OF_FIRM <= 5 then 4
   when ump.SIZE_OF_FIRM between 6 and 10 then 3
   when ump.SIZE_OF_FIRM between 11 and 25 then 2
   when ump.SIZE_OF_FIRM > 25 then 1
end as GroupTot,

Open in new window

Jeff_KingstonAuthor Commented:

Saved my Friday from becoming Saturday
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
That's what were here for.  Good luck with your project.  -Jimbo
Jeff_KingstonAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for Jeff_Kingston's comment #a39528564

for the following reason:

How many times do I have to do this?
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Assuming that my first comment answered your question, you need to click on 'Accept as solution' on that comment, which will end the question.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now