Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:48:13+00:00 2026-06-16T01:48:13+00:00

Although this technique works great for standard columns, I have run into something I

  • 0

Although this technique works great for standard columns, I have run into something I don’t understand. I am rewriting results in my query for reporting purposes and need to order by the aliased column ‘PARENT’, like so:

select fun.MODULE_ID
    , fun.FUNCTION_ID
    , COALESCE(fun.parent_function, fun2.function_id) as PARENT
    , fun.DESCRIPTION
    , fun.FUNCTION_PURPOSE
from MODULE_FUNCTION fun
LEFT JOIN MODULE_FUNCTION fun2
    ON fun.function_id = fun2.function_id
    AND fun2.function_id IN (SELECT parent_function FROM MODULE_FUNCTION)
ORDER BY MODULE_ID
    , PARENT
    , FUNCTION_ID

This works great, but my column ‘PARENT_FUNCTION’ and its alias ‘PARENT’ contain nulls. I would like these to be at the bottom. So when I do this:

ORDER BY MODULE_ID
    , case when PARENT is null then 1 else 0 end, PARENT
    , FUNCTION_ID

I get ” Invalid column name ‘PARENT’. “

Any ideas? (Still very new with SQL!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:48:14+00:00Added an answer on June 16, 2026 at 1:48 am

    SQL Server won’t let you use a column alias elsewhere in the query except in an ORDER BY clause (but not in an expression within ORDER BY), so you have to retype the original column definition. For a more in depth explanation of this (much better than I could give) please see this page

    try this:

    ORDER by MODULE_ID
       , case when COALESCE(fun.parent_function, fun2.function_id) is null then 1 else 0 end
       , FUNCTION_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time posting here, although I have gotten many great tips
Although this code is from an algorithm text, I have a bit of a
This is a follow on from my previous question although this is about something
I have the SQL2008 version of SMO and although it uses this class internally
UPDATE: This issue has been fixed as of Xcode 4.6! This technique now works
Im sure this is a simple technique although I can't find an answer so
Although this is FAQ i still couldn't find a suitable solution. I'd like to
A colleague of mine asked me to write a homework for him. Although this
According to this website : Although GSM operates in duplex (separate frequencies for transmit
I am using the jQuery-File-Upload widget (although I believe this question can generalize to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.