Solved

MS SQL order by

Posted on 2011-03-10
3
369 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

830 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