What is the equivalent of the IIF command in SQL Server?

A. In Microsoft Access you would use:

Select iif(field>10,"large", "small") as Size from Table

With SQL Server, use the CASE command

SELECT Size = 
CASE
WHEN field > 10 THEN "large"
ELSE "small"
END
from Table


See also, "Enabling .NET on SQL Server" and "More SQL Server Tools."

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish