iif and group by

oaishm

Board Regular
Joined
Jan 30, 2009
Messages
97
I have this:
Code:
select iif(very long iif statement) as order_number, mid([a],1,2) as larry,more items
from ...
group by iif(very long iif statement), mid([a],1,2)
I get invalid procedure call

If I change it to
Code:
select iif(very long iif statement) as order_number, mid([a],1,2) as larry,more items
from ...
group by [order_number], mid([a],1,2)

of course then the iif statement is not part of an aggregate function

So I tried
Code:
select first(iif(very long iif statement)) as order_number, mid([a],1,2) as larry,more items
from ...
group by [order_number], mid([a],1,2)
and it wants a paramter for order_number

and to make sure that the iif in the where clause was the actual problem, I did:
Code:
select first(iif(very long iif statement)) as order_number, mid([a],1,2) as larry,more items
from ...
group by mid([a],1,2)

which works but is not what I want. So, how does access sql work with aliases and such. In MySql, this took two seconds because you can use the alias anywhere
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
One way is to imbed your calcualtions into a subquery, i.e.

Code:
select s.order_number, s.larry, s.other items
from
(select iif(very long iif statement) as order_number, mid([a],1,2) as larry,more items
from ...) as s
group by s.order_number, s.larry
 
Upvote 0
I tried the nested select and I even tried putting it into two different queries. Alas, still didn't work. This is down right spooky. Dump the first query into a table and group on that first table, then it works, but surely this isn't how vba was invented?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top