all groups > sql server odbc > september 2004 >
You're in the

sql server odbc

group:

Transact SQL Syntax


Transact SQL Syntax bill morgan
9/30/2004 4:35:40 PM
sql server odbc:

Hi ...

I am having to switch from Access queries to Access pass-
through queries because the SQL Server 2000 tables are
getting too large (I connect to SQL Server with Access -
ODBC connection).

I can do most of the translation between Access SQL and
Transact SQL, except for conditional statements.

Can you tell me how to write the following sample Access
query in Transact SQL (using either IF/THEN or CASE
statements?

You answer will help me out a lot. Thank you in advance.


SELECT Items.SKU, Items.AverageCost, Items.DefaultCost,

IIf([AverageCost]=0,[DefaultCost],IIf([AverageCost]=Null,
[DefaultCost],[AverageCost])) AS MyCalcField

FROM Items;
RE: Transact SQL Syntax dwh2200
10/1/2004 11:35:18 AM
You just have to imbed your case statements - much in the same way you
imbedded the iif statements for access...

SELECT Items.SKU, Items.AverageCost, Items.DefaultCost,
CASE [AverageCost]
WHEN 0 THEN [DefaultCost]
ELSE CASE
WHEN [AverageCost] IS NULL THEN [DefaultCost]
ELSE [AverageCost]
END
END AS MyCalcField,
....



[quoted text, click to view]
RE: Transact SQL Syntax bill morgan
10/1/2004 4:42:12 PM
Crystal clear (and it worked!) ... thanks for your help.

[quoted text, click to view]
AddThis Social Bookmark Button