sorting and order by with nulls on the bottom after executing query

excel sql vba..

Is there a way in sql in vba to make nulls go to the bottom of the query instead of the top.

i found plety of examples but none seem to work?

for vba...

How does one use the "SWITCH" clause that includes sql with "where" statements and 3 fields to sort by ?
LVL 3
FordraidersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ fanpages ]IT Services ConsultantCommented:
Hi,

Is there a way in sql in vba to make nulls go to the bottom of the query instead of the top.

You could include an IIF(...) statement that tests for the presence of a Null & then re-assigns to a very high, or very low, value depending on the sort order, otherwise the non-Null value is used instead.

For example:

ORDER BY
IIf(IsNull([Column_Name]), "zzzzzzzzzz", [Column_Name]) ASC

or

ORDER BY
IIf(IsNull([Column_Name]), "!!!!!!!!!!", [Column_Name]) DESC


How does one use the "SWITCH" clause that includes sql with "where" statements and 3 fields to sort by ?

Please could you elaborate on your question with names of the "fields" & describe what you are trying to achieve in more detail?

Thank you.

BFN,

fp.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PortletPaulfreelancerCommented:
Confused.  What SQL? Excel as topic, VBA as discussion.

If you executing an SQL query into a dbms such as SQL Server or Oracle please provide the query and we can make recommendations. It might involve using a case expression similar to the IIF shown above e.g.

order by CASE WHEN x IS NULL THEN 'zzzzzzzzzzz' ELSE x END, ....

- but there may be other opportunities depending on the query itself and the dbms being used. (e.g. Oracle natively has NULLS First/NULLS Last)

please indicate dbms vendor and version (if this comment is relevant).
0
FordraidersAuthor Commented:
Thanks
0
[ fanpages ]IT Services ConsultantCommented:
You're welcome :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.