Solved

MS SQL order by

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

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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

809 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