Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 13
Default Microsoft Query and IIf

I build simple Excel queries through Excel's Microsoft Query and send
them to clients. They operate off a SQL Server database.

Is there a way to use the IIf function or Case When statement in one of
these .dqy queries? When I try to use IIf, MS Query doesn't complain
about IIf, but I can't get past an "Incorrect syntax near '=' message
when I try to run the query.

Here's part of my query:

Sum(IIf(CRType='W', -CRAmount, CRAmount))

I've also tried without success the following:

Sum(Case When CRType="W" Then -CRAmount Else CRAmount End)

Any ideas? Is it even possible? This needs to be done in Microsoft Query
and saved as a .dqy file. I can do this using Access or VBA in Excel, so
I am not looking for that type of solution.

Thanks for looking.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 84
Default Microsoft Query and IIf

Oh, you were so close. Here's the right way to write the Case statement:

Sum(Case CRTYPE when "W" then -CRamount Else CRamount End)

"steveh" wrote:

I build simple Excel queries through Excel's Microsoft Query and send
them to clients. They operate off a SQL Server database.

Is there a way to use the IIf function or Case When statement in one of
these .dqy queries? When I try to use IIf, MS Query doesn't complain
about IIf, but I can't get past an "Incorrect syntax near '=' message
when I try to run the query.

Here's part of my query:

Sum(IIf(CRType='W', -CRAmount, CRAmount))

I've also tried without success the following:

Sum(Case When CRType="W" Then -CRAmount Else CRAmount End)

Any ideas? Is it even possible? This needs to be done in Microsoft Query
and saved as a .dqy file. I can do this using Access or VBA in Excel, so
I am not looking for that type of solution.

Thanks for looking.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 13
Default Microsoft Query and IIf

Thanks, Bob. Actually either one works, but I had to edit the SQL and
couldn't do it "graphically." Also, I mistyped -- had to use single
quotes instead of double quotes around the W. I like your syntax better,
though.

But an odd thing happens. It takes out all the aliases in my query, and
I don't have any label for the result. If I type in:

Sum(Case CRTYPE when 'W' then -CRamount Else CRamount End) AS Balance

When I run the query and view the SQL, it shows

Sum(Case CRTYPE when 'W' then -CRamount Else CRamount End)

(AS Balance is missing.) Any suggestions?


BobT wrote:
Oh, you were so close. Here's the right way to write the Case statement:

Sum(Case CRTYPE when "W" then -CRamount Else CRamount End)

"steveh" wrote:

I build simple Excel queries through Excel's Microsoft Query and send
them to clients. They operate off a SQL Server database.

Is there a way to use the IIf function or Case When statement in one of
these .dqy queries? When I try to use IIf, MS Query doesn't complain
about IIf, but I can't get past an "Incorrect syntax near '=' message
when I try to run the query.

Here's part of my query:

Sum(IIf(CRType='W', -CRAmount, CRAmount))

I've also tried without success the following:

Sum(Case When CRType="W" Then -CRAmount Else CRAmount End)

Any ideas? Is it even possible? This needs to be done in Microsoft Query
and saved as a .dqy file. I can do this using Access or VBA in Excel, so
I am not looking for that type of solution.

Thanks for looking.

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



All times are GMT +1. The time now is 11:08 AM.

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

About Us

"It's about Microsoft Excel"