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
 Transact-SQL (2000)
 complicated query

Author  Topic 

ts_abbott@hotmail.com
Starting Member

36 Posts

Posted - 2005-03-23 : 06:59:08
Hi,

I have 3 tables - Prizes, Winners, Images.

Winners has 6 columns - OfferedPrize1, OfferedPrize2, ... OfferedPrize6.

Some of the above mentioned columns may be null.

Images (columns Prizeid, ImageName) can contain multiple rows for each prize but doesn't necessarily contain any.

i need to make a query which will always return exactly 6 rows by joining OfferedPrize1-6 to Prizes & Images. The idea is that if only 3 prizes have been offered then it will make up the missing rows by repeating the prizeid's it does have and selecting a different image for each.

Anyone got any ideas on where to start?

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-03-23 : 07:05:27
1. query to identify the 3/4 prizes won
2. seperate query to list "upto 6 prizes"...ie there a randomness element to the image???...ie "selecting a different image"...what criteria drives this selction.
3. union the 2 results sets together....and select "TOP 6"....with results from #1 sorted to the top.
Go to Top of Page
   

- Advertisement -