We help IT Professionals succeed at work.
Get Started

update field on random basis

johnnyg123
johnnyg123 asked
on
139 Views
Last Modified: 2015-04-07
Here is some sample data I have from a table named  MailList  (SQL Server 2008)
(For space purposes I have left out Street address and Zip Code)


PersonID   FirstName     LastName       City                      State       MailTo
1                  Al                   Doe                  Dallas                  TX             Y
2                  Jill                   Doe                  Dallas                  TX             Y    
3                  Jane               Doe                  Austin                  TX             Y      
4                  John               Smith               Houston            TX             Y      
5                  Ron                White               New York           NY            Y
6                  Beth               Doe                  Los Angeles       CA            Y
7                  Bart               Doe                  Rochester          NY            Y    
8                  Jim                  Jones               Burbank             CA            Y  
9                  Jack                Black               Annaheim           CA           Y      

In an effort to support a marketing mail campaign I need to take a random number of records for a given state and update the mailto flag from Y to N

Lets say the numbers are as follows

TX= 2

CA = 1



After the query

PersonID   FirstName     LastName       City                      State       MailTo
1                  Al                   Doe                  Dallas                  TX             N
2                  Jill                   Doe                  Dallas                  TX             Y    
3                  Jane               Doe                  Austin                  TX             Y      
4                  John               Smith               Houston            TX             N      
5                  Ron                White               New York           NY            Y
6                  Beth               Doe                  Los Angeles       CA            N
7                  Bart               Doe                  Rochester          NY            Y    
8                  Jim                  Jones               Burbank             CA            Y  
9                  Jack                Black               Annaheim           CA           Y      


Not quite sure the best way to approach this
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
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
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