Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 merging rows

Author  Topic 

n3xus
Starting Member

6 Posts

Posted - 2011-04-14 : 04:37:40
[CODE]Subject 1 2 3
------------ ------------- ------------- -------------
English 80 NULL NULL
English NULL NULL 95
English NULL 75 NULL[/CODE]

First of all I do know that this should be handled at presentation layer but I'm forced to do it on SQL Select statement.

I'm Trying to display it as following.

[CODE]Subject 1 2 3
------------ ------------- ------------- -------------
English 80 75 95[/CODE]

Is it possible to do it?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-14 : 04:47:49
quote:
First of all I do know that this should be handled at presentation layer but I'm forced to do it on SQL Select statement.

Not really, such things should be done in the Data layer rather than presentation layer. Else you will be sending multiple lines to the client just to sum it up and display as one line.

you can use GROUP BY with SUM() to get the required result

select Subject, sum([1]), sum([2]), sum([3])
from yourtable
group by Subjct



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2011-04-14 : 12:50:03
it is best to handle issues from design point of view instead of creating cirque du soleil sql queries to handle fundamental design issues.

so the question I would ask is why is it in entered into the table as such? you solve that and you solve everything else.

If you don't have the passion to help people, you have no passion
Go to Top of Page
   

- Advertisement -