# SQL output using IIF()



## imfarhan

Hi  SQL Gurus
The following query last column  IIF( x=1,  IIF( )) not showing the right reulst . 
I would expect where the Source = "Initial Budget" and "WTE_Total" should show "Yes" and other rows sould show "NO"
but if you see the output in the screen below showing wrong and you can also see the IIF() condition in the SQL below as well
appreciate your help
Thanks
Farhan






		SQL:
__


SELECT qry_bp_revised_adjustment_output_07.source,
       qry_bp_revised_adjustment_output_07.id,
       qry_bp_revised_adjustment_output_07.account_id,
       qry_bp_revised_adjustment_output_07.fin_yr,
       qry_bp_revised_adjustment_output_07.period,
       qry_bp_revised_adjustment_output_07.model_id,
       qry_bp_revised_adjustment_output_07.comment,
       qry_bp_revised_adjustment_output_07.elements,
       Sum(qry_bp_revised_adjustment_output_07.bud_val)            AS       SumOfBud_Val,
       qry_bp_revised_adjustment_output_07.bud_profile,
       qry_bp_revised_adjustment_output_07.wte_profile,
       Sum(qry_bp_revised_adjustment_output_07.sumofwte_val)       AS       SumOfSumOfWTE_Val,
       Sum(qry_bp_revised_adjustment_output_07.wte_val_adjustment) AS       SumOfWTE_Val_Adjustment,
IIF(
   qry_bp_revised_adjustment_output_07.source = "Initial Budget",     
          IIF(qry_bp_revised_adjustment_output_07.source = "WTE Total",     
           "Yes"  ,"NO"
)) AS Total_WTE
 
FROM   qry_bp_revised_adjustment_output_07
GROUP  BY qry_bp_revised_adjustment_output_07.source,
          qry_bp_revised_adjustment_output_07.id,
          qry_bp_revised_adjustment_output_07.account_id,
          qry_bp_revised_adjustment_output_07.fin_yr,
          qry_bp_revised_adjustment_output_07.period,
          qry_bp_revised_adjustment_output_07.model_id,
          qry_bp_revised_adjustment_output_07.comment,
          qry_bp_revised_adjustment_output_07.elements,
          qry_bp_revised_adjustment_output_07.bud_profile,
          qry_bp_revised_adjustment_output_07.wte_profile;


----------



## james_lankford

maybe i'm reading it wrong, but aren't you checking 
if
qry_bp_revised_adjustment_output_07.source = "Initial Budget" 
AND    
qry_bp_revised_adjustment_output_07.source = "WTE Total"

it can't be both at the same time


----------



## imfarhan

james_lankford said:


> maybe i'm reading it wrong, but aren't you checking
> if
> qry_bp_revised_adjustment_output_07.source = "Initial Budget"
> AND
> qry_bp_revised_adjustment_output_07.source = "WTE Total"
> 
> it can't be both at the same time


Yes I think you are right.
How can I use OR within my IIF() condition 
Thanks


----------



## imfarhan

imfarhan said:


> Yes I think you are right.
> How can I use OR within my IIF() condition
> Thanks


IIf(Eval([CountryRegion] In ("Canada","USA","Mexico")),"North America","Other")
I will try above n update here


----------



## imfarhan

imfarhan said:


> IIf(Eval([CountryRegion] In ("Canada","USA","Mexico")),"North America","Other")
> I will try above n update here


Thanks James the following IIF() with OR is working



		SQL:
__


    IIF(
         qry_bp_revised_adjustment_output_07.source = "Initial Budget"
      OR
        qry_bp_revised_adjustment_output_07.source = "WTE Total",
       "Yes","NO") AS Total_WTE


----------

