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 : 12:41:05
|
| how can I select the value for the first query in the UNION to always appear no matter what the second query throws?Exampleselect description, sum(data) from (select a.description as description, a.data as dataUNIONselect b.description as description, b.data as data)group by description |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-01-06 : 12:46:03
|
| It will always appear - the second query will add values it won't cause them to be dropped.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
dalmada
Starting Member
12 Posts |
Posted - 2006-01-06 : 12:53:38
|
| DBut the thing is the second query has blank values so it adds a new line with the description in blank, so now I have two lines instead of one |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-01-06 : 12:55:18
|
| Yep - you still have the value from the first query which is what you want.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
dalmada
Starting Member
12 Posts |
Posted - 2006-01-06 : 12:59:30
|
| I want one line with all the info...Not twoWith the description from the first query |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-01-06 : 13:26:28
|
| If you only want one row then you shuoldn't be grouping by description as that is only useful if you have multiple descriptions and want that to match the values from the two queries.select max(description), sum(data) from (select a.description, a.data from aUNIONselect '', b.data from b) a==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|