• 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.
0
Scamquist
Asked:
Scamquist
  • 2
1 Solution
 
lwadwellCommented:
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
0
 
lwadwellCommented:
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
0
 
ScamquistAuthor Commented:
Thank you for the assist.
0

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