Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Confirm My Queries
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01519113
Message ID:
01519145
Views:
34
>I have to make updates to a critical production Voters table called tblCamp_ct. I'm looking for another set of eyes on this before I execute it. It should be really simply but I have to be sure.
>
>The requirements are:
>
>
>1) Anyone who voted R in 2010 is an R regardless of if they voted D in 2008 or 2006
>2) Anyone who voted R in 2008 is an R unless they voted D in both 2010 and 2006
>3) Anyone who voted R in 2006 is an R unless they voted D in either 2008 or 2010
>
>
>My queries then should be
>
>
>1) "Anyone who voted R in 2010 is an R regardless of if they voted D in 2008 or 2006"
>

>
>which means
>
>
>UPDATE tblCamp_ct SET Party = 'R' WHERE Voted2010 = 'R'   -- Don't worry about 2006 or 2008
>
>
>
>
>2) "Anyone who voted R in 2008 is an R unless they voted D in both 2010 and 2006"
>

>
>which means,
>
>
>UPDATE tblCamp_ct SET Party = 'R' WHERE Voted20008 = 'R' AND (Voted2010 != 'D' AND Voted2006 != 'D' )
>
>
>
>
>3) "Anyone who voted R in 2006 is an R unless they voted D in either 2008 or 2010"
>

>
>which means,
>
>
>UPDATE tblCamp_ct SET Party = 'R' WHERE Voted20006 = 'R' AND (Voted2008 != 'D' AND Voted2010 != 'D' )
>
>
>
>Sound about right?



What if all fields are 'D'?
You wouldn't update Party field to anything.
Maybe this:
UPDATE tblCamp_ct
       SET Party = CASE WHEN Voted2010 = 'R'
                             THEN 'R'  -- Don't worry about 2006 or 2008
                        WHEN Voted2008 = 'R' AND (Voted2010 != 'D' AND Voted2006 != 'D' )
                             THEN 'R'
                        WHEN Voted2006 = 'R' AND (Voted2008 != 'D' AND Voted2010 != 'D' )
                             THEN 'R'
                   ELSE ??????? END
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform