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 6980571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:02:23+00:00 2026-05-27T18:02:23+00:00

I have a (sql server 2008) query as follows: Select *, column1+column2 as alias1

  • 0

I have a (sql server 2008) query as follows:

 Select *, column1+column2 as alias1
 From complaints
 Order by 
 Case 
   When @param1 = 'filedate' then filedate
   When @param1 = 'calc' then alias1
 End

This doesn’t work, because ordering on an alias in a case statement is not allowed, it doesn’t recognize alias1.

Is there another way this can be done?

Thanks

  • 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-05-27T18:02:24+00:00Added an answer on May 27, 2026 at 6:02 pm

    either put it in a CTE and then order by…

    ; with cteQuery as (Select *, column1+column2 as alias1 from complaints)
    SELECT * from cteQuery Order by 
    Case 
       When @param1 = 'filedate' then filedate
       When @param1 = 'calc' then alias1
     End
    

    or just duplicate what the alias actually refers to…

    Select *, column1+column2 as alias1
     From complaints
     Order by 
     Case 
       When @param1 = 'filedate' then filedate
       When @param1 = 'calc' then column1+column2
     End
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2008 query SELECT TOP 10 * FROM T WHERE
I have a Microsoft SQL Server 2008 query that returns data from three tables
In sql server 2008, I have the following query: select c.title as categorytitle, s.title
DB: Sql Server 2008. I have a really (fake) groovy query like this:- SELECT
Background: I'm using SQL Server Management Studio 2008 and I have a query window
I have SQL Server 2008. I run a query in a table on a
I am using SQL Server 2008. Is there a way to select from multiple
Does the text query editor in MS SQL Server 2008 R2 have a SQL
I have a SQL Server 2008 Express R2 instance authenticating from Active Directory. Users
Me and my colleagues have a question regarding SQL Server 2008 query length and

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.