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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,216,189
Messages
6,129,406
Members
449,509
Latest member
ajbooisen

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