• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • 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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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