If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > If statment to SQL ??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-06, 07:00
ahmed_zedan ahmed_zedan is offline
Registered User
 
Join Date: Dec 2004
Posts: 11
If statment to SQL ??

I have a statement written in microsoft access query, and I want to convert it to be applied on SQL Database or view or SQL query bilder or on ASP.Net
microsoft Access Statement:

Toal paid : IIf([TP$]>0,(Format([TP$],'Fixed') & ' $')) & IIf([TPU]>0,(Format([TPU],'Fixed') & ' Euro')) & IIf([TP$]+[TPU]=0,0)

The result is a column as following

30 $
250 Euro
20 $
0 $

How I can apply it in SQL view ? ?
Thanks;
Reply With Quote
  #2 (permalink)  
Old 01-19-06, 07:20
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
Is this an ASP question, a SQL question, a SQL Server Question or JET Question?

AFAK you can only use IIF in JET, its not available in any other SQL engine
other SQL's use things such as case, switch etc.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 01-20-06, 18:21
disruptivehair disruptivehair is offline
Registered User
 
Join Date: Dec 2005
Location: Texas
Posts: 100
Quote:
Originally Posted by ahmed_zedan
I have a statement written in microsoft access query, and I want to convert it to be applied on SQL Database or view or SQL query bilder or on ASP.Net
microsoft Access Statement:

Toal paid : IIf([TP$]>0,(Format([TP$],'Fixed') & ' $')) & IIf([TPU]>0,(Format([TPU],'Fixed') & ' Euro')) & IIf([TP$]+[TPU]=0,0)

The result is a column as following

30 $
250 Euro
20 $
0 $

How I can apply it in SQL view ? ?
Thanks;
Ahmed, SQL doesn't support IIF; it's a VBA function. You can duplicate its functionality by using CASE, though.

For example:

Value = CASE WHEN [expression] THEN [expression] ELSE [expression] END

or

VALUE = CASE WHEN columna.thing IS NULL THEN columnb.thing ELSE columna.thing END....for example.
Reply With Quote
  #4 (permalink)  
Old 01-24-06, 08:24
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by ahmed_zedan
IIf([TP$]>0,(Format([TP$],'Fixed') & ' $')) & IIf([TPU]>0,(Format([TPU],'Fixed') & ' Euro')) & IIf([TP$]+[TPU]=0,0)
I am not familiar with Access; if I understand your query correctly, the standard SQL equivalent would be
Code:
SELECT CASE WHEN TP$ > 0 THEN TP$ || ' $'
            WHEN TPU > 0 THEN TPU || ' Euro'
            ELSE '-'
            END
FROM   tablename
(which assumes that TPU and TP$ will not both be strictly positive at the same time).
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On