Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Query to return record by percent chance

Avatar of Type25
Type25 asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008
7 Comments1 Solution342 ViewsLast Modified:
We have a table with a list of advert campaigns, each campaign is assigned a percent value and the cumulative value will always add up to 100. Mixed in with this is a region, you can have a region of 'ALL' and different regions, 'GB', 'FR' etc..
The ALL region + the specific region must add up to no more than 100%, if it's under then we can use a default advert campaign.

For example, our table looks like this:

AdvertCampaigns
----------------------
CampaignID int identity(1,1)
CampaignName varchar(100)
Region varchar(5)
CampaignPercent int

Example Data
----------------
1, Example1, 'ALL', 70
2, Example2, 'GB', 30
3, Example3, 'FR', 20

So if you're in GB then ALL + GB add up to 100, if you're in france then FR + ALL = 90, the remaining 10% would be a generic campaign.

So, basically, i'm trying to run a function which will return a random campaignID based on the percentage chance of it coming out, but can't seem to work out the best way of doing it.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answers