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 2000 Forums
 SQL Server Development (2000)
 Is a union the right thing?

Author  Topic 

label
Posting Yak Master

197 Posts

Posted - 2003-08-21 : 15:43:13
I have the following query:


select heading, productID
from smc_new_products.dbo.marketingnewproductproducts
where productweek=1
union
select heading, productID
from smc_new_products.dbo.marketingnewproductproducts
where featuredProduct=1


That currently returns results like this:

EVS7 | 140
SV1000/2000 | 88


What I want, instead, is to return both results in one row.

How do I flatten the current result which is two rows into 1 ?

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-21 : 15:46:04
This will still give you two rows, but it eliminates the union:

select heading, productID
from smc_new_products.dbo.marketingnewproductproducts
where productweek = 1 or featuredProduct = 1

How would you like the result set to look when combined into one row?


Tara
Go to Top of Page

label
Posting Yak Master

197 Posts

Posted - 2003-08-21 : 15:53:59
quote:
Originally posted by tduggan
How would you like the result set to look when combined into one row?



Product Header 1 | ProductID 1 | Featured Header 2 | FeaturedID

It'll save me having to loop through the results when I'm populating the labels on my web page.

Thanks.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-21 : 16:06:06
Check out this article:

[url]http://www.sqlteam.com/item.asp?ItemID=11021[/url]

Just remove the comma from the query. The part that you are interested in is at the bottom.

Tara
Go to Top of Page
   

- Advertisement -