Solved

MS SQL order by

Posted on 2011-03-10
3
366 Views
Last Modified: 2012-05-11
Is it possible to do a MS SQL query where the order by is the sum of two fields?

If I have two numeric fields in the table and want the query to sort by the sum of those fields.
0
Comment
Question by:cdjohn31
3 Comments
 
LVL 18

Expert Comment

by:Cluskitt
ID: 35093427
Yes, you can. The sum of two fields is, as far as SQL is concerned, just a field. It is calculated from 2 others, but it's computed as if it's a field like any other.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 35093428
Yes, you can do something like:
SELECT Value1, Value2, [Stuff] FROM SampleTable ORDER BY Value1+Value2

Open in new window

0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35093482
ye you can like this
select col1,col2,(col1 +col2) as sumofcol from tablename
order by (col1 +col2)
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now