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)
 Random select based on weightage

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 campaign
based on the above criteria and returns a resultset which is
something like
campaign A 3
campaign B 5
campaign C 7
....

The procedure is something like

DECLARE
@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 procedure
SET @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 Weight

FROM Campaign
WHERE
(
datebegin < GETDATE()
AND dateend > GETDATE()
)
OR Occupation = ''
OR Age = ''
OR Income = ''
OR State = ''
OR Country = ''
OR Category = 'Gambling'
OR URL = ''
ORDER BY Weight


The CASE statements handle the weighting of the
records. We need to be able to utilize that weight to
create a percentage chance of one of those records to
be 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 calulated

Thanks in advance
Sangeetha
   

- Advertisement -