a SQL "If" query

dsundy2003

New Member
Joined
Dec 26, 2002
Messages
40
Hi
I'm looking to write a View in sql (using enterprise manager) which does pretty much what Access queries do:

The syntax in access is: SELECT IIf([insstdte]<#10/1/2004#,"Now till Sep 2004","After Sept 2004") AS Expr1 FROM .....

Now how the heck can I say that in a SQL query, using a sql server database.
Pls help

(I know its not strictly an MS Access question, but its kinda related...)

Darryn :rolleyes:
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Can you create an OBDC connection to the SQL server? Because if so you can query in Access SQL syntax. The SQL should be the same unless you are trying to run a "Pass through" query or are using Oracle.

To create the connection in Acces just goto tables-Link, then hit the dropdown at the bottom of the dialog box and scroll down to OBDC databases.

Then enter the DSN information and you should be all set
 
Upvote 0
Thanks Jmersing

Does that mean that sql does not have an 'iif' function like access does ?
Surely not ...
 
Upvote 0
Yes it does tthe syntax is like this

select iif([yourfieldname]>1,"Yes","No") as answer
from yourtable;
 
Upvote 0
I created a new View and used your syntx that you sugested:
SELECT iif([user id] = 'Charlotte', " Its Charlotte","Its Not Charlotte") AS answer
FROM dbo.['raw data'];

But I still get this error "Error in list of function arguments: '=' not recognized.
Unable to parse query text."

Help !

Darryn :(
 
Upvote 0
You should have double quotes around Charlotte


SELECT iif([user id] = "Charlotte", " Its Charlotte","Its Not Charlotte") AS answer
FROM dbo.[raw data];

and no single quotes around your table name

what is dbo ? seems like a strange name for a table
 
Upvote 0

Forum statistics

Threads
1,221,805
Messages
6,162,081
Members
451,738
Latest member
gaseremad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top