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 |
|
cookie
Starting Member
1 Post |
Posted - 2001-01-19 : 13:07:47
|
| Hi,We have an Ad server that dishes out campaign ads based on a user's profile data(such as occupation, age, country etc)when that user logs in to a site. The capaigns are stored in a table with various fields such as occupation, age,coutry etc.The following procedure calculates the weightage for each campaignbased on the above criteria and returns a resultset which is something likecampaign A 3campaign B 5campaign C 7....The procedure is something likeDECLARE@Occupation varchar(50),@Age varchar(50),@Income varchar(50),@State varchar(50),@Country varchar(50),@Category varchar(50),@URL varchar(50)#### These are going to be the user's profile data which is passed to the procedureSET @Occupation = ''SET @Age = ''SET @Income = ''SET @State = ''SET @Country = ''SET @Category = 'Gambling'SET @URL = ''SELECT Campaign,((CASE Occupation WHEN @Occupation THEN 1 ELSE 0 END)+(CASE Age WHEN @Age THEN 1 ELSE 0 END)+(CASE Income WHEN @Income THEN 1 ELSE 0 END)+(CASE State WHEN @State THEN 1 ELSE 0 END)+(CASE Country WHEN @Country THEN 1 ELSE 0 END)+(CASE Category WHEN @Category THEN 1 ELSE 0 END)+(CASE URL WHEN @URL THEN 1 ELSE 0 END)) AS WeightFROM CampaignWHERE( datebegin < GETDATE()AND dateend > GETDATE())OR Occupation = ''OR Age = ''OR Income = ''OR State = ''OR Country = ''OR Category = 'Gambling'OR URL = ''ORDER BY WeightThe CASE statements handle the weighting of therecords. We need to be able to utilize that weight tocreate a percentage chance of one of those records tobe selected. i.e we need to modify this SQL statement to one where one of the records is chosen randomly based on the total weightage calulatedThanks in advance Sangeetha |
|
|
|
|
|
|
|