Attaching a column for the case statement results in sql query

I would like to name my case statement values so I can display it as a column to see what's happening. Here is my code:

SELECT NavMenu.*  
 from NavMenu 
 left outer join navmenu as nm on navmenu.parentnavmenuid = nm.navmenuid 
 WHERE 
 NavMenu.NavMenuGroupCode IN (2609) 
 AND 
 NavMenu.NavMenuName  LIKE '%test%'  

 order by navmenu.navmenugroupcode desc,  
 case when navmenu.isparentnavmenu = 1 then navmenu.listorder 
 Else nm.listorder 
 END ASC, 
 case when navmenu.isparentnavmenu = 1 then 0 
 else 1 
 END ASC,
  NavMenu.ListOrder

Open in new window



I have another query that uses:
End as 'GlobalOrder'

Open in new window


But when I try something like that with this, it doesn't work.

Help?

thanks!
LVL 2
Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
figured it out....



SELECT NavMenu.*,

sortvalue =
 case when navmenu.isparentnavmenu = 1 then navmenu.listorder
when navmenu.isparentnavmenu = 0 then 0
 else 1
 END
 
 from NavMenu
 left outer join navmenu as nm on navmenu.parentnavmenuid = nm.navmenuid

 WHERE
 NavMenu.NavMenuGroupCode IN (2609)
 AND
 NavMenu.NavMenuName  LIKE '%test%'  

 order by navmenu.navmenugroupcode desc,  
 sortvalue,
  NavMenu.ListOrder
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
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Not abundantly sure why but CASE blocks are not best practice in WHERE clauses, the recommendation is to use logic like AND and OR and prentheses ( ) to handle filtering.

Also I don't see 'GlobalOrder' in your posted solution, so hard to see how that worked for you.  
Also as long as the name does not include spaces or punctuation marks other than underscore, the single quotes ' ' are not needed.
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
Query Syntax

From novice to tech pro — start learning today.