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.
| Author |
Topic |
|
dalmada
Starting Member
12 Posts |
Posted - 2006-01-06 : 10:36:05
|
| Hello.I have a problemI have a union query i.e.Select c as DESCRIPTIONsum(a) as EXECUTED'0' as PENDINGUNIONc as DESCRIPTION'0' as EXECUTED'sum(b) as PENDINGBut I Can't seem to find the way to get the results in one line. I need the description and the two columns added. How can I do this? Also, if the description on the first query has the one I want and the second one is NULL how can I use the first one without getting two lines as a result with the description and the NULL value?Thanks |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-01-06 : 10:53:46
|
| How about some sample data with expected results and a clear description of what you are trying to do? You didn't even give us a valid SELECT to start with, so it is pretty hard to guess what you need. Be specific, and we can help you quickly. |
 |
|
|
dalmada
Starting Member
12 Posts |
Posted - 2006-01-06 : 10:58:16
|
| SELECT arg.description AS DESCRIPTION,arg.total1 AS EXECUTED'0' AS PENDINGfrom momot.arg argUNIONSELECTarg.description AS DESCRIPTION,'0' AS EXECUTEDarg.total2 AS PENDINGfrom momot.arg argWHAT I GET RIGHT NOW IS THISDESCRIPTION EXECUTED PENDING RED 45 0 <NULL> 0 54WHAT I NEED ISDESCRIPTION EXECUTED PENDING RED 45 54 |
 |
|
|
dalmada
Starting Member
12 Posts |
Posted - 2006-01-06 : 11:12:38
|
| help! |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-01-06 : 11:45:55
|
wrap your existing SQL like this:SELECT MAX(DESCRIPTION) as Description, SUM(EXECUTED) as Executed, SUM(PENDING) as PendingFROM (your existing SQL) a That will turn your result from 2 lines into 1. |
 |
|
|
dalmada
Starting Member
12 Posts |
Posted - 2006-01-06 : 11:48:14
|
| didn't workI'm still getting to lines that look like thisDESCRIPTION EXECUTED PENDING RED 54 0 RED 0 45 |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-01-06 : 14:43:16
|
| What is the SQL statement that you tried? |
 |
|
|
|
|
|