Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10
Default Writing an IF statement in Microsoft Query

I'm querying our Oracle data to Excel and can't seem to get a formula return
as a new field.

I need the proper way to write this sequence:

IF(RM.RM_STD= "LOCKER",50,RM.RM_AREA*RMSTD.COST_OF_SPACE)

Which would basically say that if the room standard is a locker, we charge
$50 - otherwise, take the room area and multiply it by the cost per square
foot. But it doesn't matter how I write it...it's not working! HELP??!!!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,942
Default Writing an IF statement in Microsoft Query

hi
MS Query uses SQL and in SQL, you have to use the SQL IIf instead of the vb
IF.
and the IIf statement goes in the MSQ SQL statement ie
SELECT name, Address, ect,
IIF(RM.RM_STD= "LOCKER",50,RM.RM_AREA*RMSTD.COST_OF_SPACE) from somedatabase.

i cannot test but your IIf statement "looks" ok so good luck.

regards
FSt1




"JTurner" wrote:

I'm querying our Oracle data to Excel and can't seem to get a formula return
as a new field.

I need the proper way to write this sequence:

IF(RM.RM_STD= "LOCKER",50,RM.RM_AREA*RMSTD.COST_OF_SPACE)

Which would basically say that if the room standard is a locker, we charge
$50 - otherwise, take the room area and multiply it by the cost per square
foot. But it doesn't matter how I write it...it's not working! HELP??!!!

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10
Default Writing an IF statement in Microsoft Query

I've tried the IIF as well. It keeps returning the error "ORA-00907: missing
right parthensis". Does that help troubleshoot?
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,942
Default Writing an IF statement in Microsoft Query

hi
i am suddenly having major problem with MSQ. trying to edit a query locks up
excel. just started so i've go some major troubleshooting of my own now.
i can't peek at my SQL stuff so i'm going on memory...
i said you IIf statement looks ok but i may have crossed some wires in my
brain.
i think table names should be in brackets ie...
SELECT name, Address, ect,
IIF([RM.RM_STD]= "LOCKER",50,[RM.RM_AREA]*[RMSTD.COST_OF_SPACE]) from
somedatabase.

can any SQL experts confirm this?

Regards
FSt1

"JTurner" wrote:

I've tried the IIF as well. It keeps returning the error "ORA-00907: missing
right parthensis". Does that help troubleshoot?

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Writing an IF statement in Microsoft Query

Hi

just to check, have you declared a field for the data in the select
statement of the SQL syntax? Might be worth posting the whole SQL statement
so it can be checked, as the iif looked OK.

"JTurner" wrote:

I've tried the IIF as well. It keeps returning the error "ORA-00907: missing
right parthensis". Does that help troubleshoot?



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10
Default Writing an IF statement in Microsoft Query

If I have this query, I get the "missing right parenthesis" error:

SELECT RM.BL_ID, RM.FL_ID, RM.RM_ID, RM.AREA, RM.COUNT_EM, DP.NAME,
RM.DP_ID, DV.NAME, RM.DV_ID, RM.RM_CAT, RM.RM_STD, RM.RM_TYPE, RM.RM_USE,
RM.OPTION1, RMSTD.COST_OF_SPACE,
IIF(RM.RM_STD="LOCKER",RMSTD.COST_OF_SPACE,RM.AREA *RMSTD.COST_OF_SPACE)
FROM AFM.DP DP, AFM.DV DV, AFM.RM RM, AFM.RMSTD RMSTD
WHERE RM.DV_ID = DV.DV_ID AND RM.DP_ID = DP.DP_ID AND DP.DV_ID = DV.DV_ID
AND RM.RM_STD = RMSTD.RM_STD

If I write it this way, I get "Incorrect Column Expression":

SELECT RM.BL_ID, RM.FL_ID, RM.RM_ID, RM.AREA, RM.COUNT_EM, DP.NAME,
RM.DP_ID, DV.NAME, RM.DV_ID, RM.RM_CAT, RM.RM_STD, RM.RM_TYPE, RM.RM_USE,
RM.OPTION1, RMSTD.COST_OF_SPACE,
IIF([RM].[RM_STD]="LOCKER",[RMSTD].[COST_OF_SPACE],[RM].[AREA]*[RMSTD].[COST_OF_SPACE])
FROM AFM.DP DP, AFM.DV DV, AFM.RM RM, AFM.RMSTD RMSTD
WHERE RM.DV_ID = DV.DV_ID AND RM.DP_ID = DP.DP_ID AND DP.DV_ID = DV.DV_ID
AND RM.RM_STD = RMSTD.RM_STD

And if I write it this way, I get an "ORA-00936: missing expression" error:

SELECT RM.BL_ID, RM.FL_ID, RM.RM_ID, RM.AREA, RM.COUNT_EM, DP.NAME,
RM.DP_ID, DV.NAME, RM.DV_ID, RM.RM_CAT, RM.RM_STD, RM.RM_TYPE, RM.RM_USE,
RM.OPTION1, RMSTD.COST_OF_SPACE,
IIF([RM.RM_STD]="LOCKER",[RMSTD.COST_OF_SPACE],[RM.AREA]*[RMSTD.COST_OF_SPACE])
FROM AFM.DP DP, AFM.DV DV, AFM.RM RM, AFM.RMSTD RMSTD
WHERE RM.DV_ID = DV.DV_ID AND RM.DP_ID = DP.DP_ID AND DP.DV_ID = DV.DV_ID
AND RM.RM_STD = RMSTD.RM_STD
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10
Default Writing an IF statement in Microsoft Query

Also, for Rik_UK, I don't know how to "declare" a field. In my Excel search,
I found that I can't select something "AS" and that you would caption the
expression in the options (and turn off field names). So I'm probably missing
something...
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a query Pierre Excel Discussion (Misc queries) 2 January 28th 10 10:14 PM
Query from microsoft query- Excel 2007 טבלאות אקסל 2007 Excel Discussion (Misc queries) 0 December 24th 07 10:47 PM
Writing IF Statement Angie Excel Worksheet Functions 4 June 5th 07 10:10 PM
writing a statement newexceluser Excel Worksheet Functions 1 July 21st 06 10:15 PM
Microsoft Query rejects "nz" function in Access Query Vaughan Excel Discussion (Misc queries) 0 May 4th 05 05:20 PM


All times are GMT +1. The time now is 04:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"