SQL Server 2005 query that uses the IIF with style date bool ?


Author
Message
Dong Trien Lam
Dong Trien Lam
StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)
Group: Anonymous / Guest
Posts: 57, Visits: 251
Suppose I have TABLE with the following fields:
Quantity [number]
Price [Number]
Returns [bool]

If Returns = true, then - ([quantity]*[Price])// negative returns
If Returns = false, then ([quantity]*[Price]) // positive returns

Question using SQL Server 2005:
Inquiry following his error was in command IIF:
SELECT quantity, Price, Returns, IIF ([Returns] = 0, ([quantity]*[Price]), (-1)*([quantity]*[Price])) As Total
FROM TABLE;


SQL Syntax Errors Encountered:
The following errors were encountered while parsing the contents of the SQL pane:
Error in list of function arguments: '=' not recognized. Unable to parse query text.
Yasar Askari
Yasar Askari
StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)
Group: StrataFrame Users
Posts: 1, Visits: 7


That IIF statement only exists in MDX - the query language for SQL Server Analysis Services - the datawarehousing side of SQL Server.

Plain T-SQL does not have an IIF statement.

The best you can do in T-SQL is use the CASE.... WHEN... THEN... statement.
Dong Trien Lam
Dong Trien Lam
StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)StrataFrame User (173 reputation)
Group: Anonymous / Guest
Posts: 57, Visits: 251
Ok, thank you
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search