Using IIf in SQLCommand

Posted on 2005-03-22
Medium Priority
Last Modified: 2006-11-17
Im trying to pass this string to SQL from Visual Studio.net and I'm receiving the following ERROR : Incorrect syntax near '='
mySqlCommand.CommandText = "SELECT Table.acct_rep, Table..email, Table..cellular, Table..fax, IIF(Table..admin='Y','Owner','User') As newfield, Table..seq_id FROM [VS_DAT].[dbo].[Table] ORDER BY Table..acct_rep"

Can anyody help to write this in the right way?

Question by:NeGueSa
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 34

Expert Comment

by:Brian Crowe
ID: 13604520
There is no IIF in SQL

SELECT Table.acct_rep, Table..email, Table..cellular, Table..fax, (CASE WHEN Table..admin='Y' THEN 'Owner' ELSE 'User' END) As newfield, Table..seq_id FROM [VS_DAT].[dbo].[Table] ORDER BY Table..acct_rep
LVL 34

Accepted Solution

Brian Crowe earned 2000 total points
ID: 13604533
need to remove the double periods in your column references as well

SELECT Table.acct_rep, Table.email, Table.cellular, Table.fax, (CASE WHEN Table.admin='Y' THEN 'Owner' ELSE 'User' END) As newfield, Table.seq_id FROM [VS_DAT].[dbo].[Table] ORDER BY Table.acct_rep

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question