SQL Server: Update Zips, see if zips exist, Update Carrier to correspond with Zips

37 views Asked by At
vcAccountNum | iZone | vcZipStart | vcZipEnd | vcCarrier1 
| vcCarrier2 | vcTerminal1 | vcTerminal2 | DAS

I want to see if a zip exists out of 6000 zips. The zipEnd and zipStart are the same. If the ABC Carrier is either/or vcCarrier1 or vcCarrier2 then vcTerminal1 and/or vcTerminal2 need to be updated with a new code, example JFK.

I also need to flag DAS Y or N depending on the zip.

I am thinking of using IN for all of the zips.

I have to do this every so often. Looking at a way to make a SP or just get this one done without spending a day on it.

Thank You,

1

There are 1 answers

2
shA.t On

I think you are searching for a query like this:

UPDATE yourTable
SET
    vcTerminal1 = CASE WHEN vcCarrier1 = 'ABC Carrier' THEN 'NewCode' ELSE vcTerminal1 END,
    vcTerminal2 = CASE WHEN vcCarrier2 = 'ABC Carrier' THEN 'NewCode' ELSE vcTerminal2 END,
    DAS = CASE WHEN 'zip Code' = 'Depeneds' THEN 'Y' ELSE 'N' END
WHERE
    'zip Code' BETWEEN vcZipStart AND vcZipEnd