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

SQL If Statement problem

I am using Microsoft SQL Server Management Studio 2008r.  I am trying to create a query that will assign an ABC value based on a cost.  I have no problems doing this in Access, buy SQL is just differenet enough to be a problem.

the component of the select statement is

if(im.cost_avg < 3,'C',if(im.cost_avg > 250,'A','B')) as ABC

I am not sure what I am missing.
Any help will be appreciated.
  • 2
1 Solution
I think SQL Server it is iif - two i's. :
  iif(im.cost_avg < 3,'C',iif(im.cost_avg > 250,'A','B')) as ABC
A CASE statement is commonly used instead of iif ... e.g.
  CASE WHEN im.cost_avg < 3 THEN 'C'
            WHEN im.cost_avg > 250 THEN 'A'
            ELSE 'B' END as ABC
ScamquistAuthor Commented:
Thank you for the assist.
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.

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