Mateus he inherited some code where half the variables were given names like strAux1
and strAux2
. It was a data-driven application, and the data had some conventions that weren’t always ideal; eg every city also has an associated abbreviation stored in the name field, eg “SAO PAULO (SP)” and “RIO DE JANEIRO (RJ)”.
The original developers wanted to be able to represent the names of cities without an abbreviation, so they wrote this one:
RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(UPPER(ISNULL(C.CITY,'')),'(RS)',''),
'(SC)',''),'(PR)',''),'(SP)',''),'(MG)',''),'(RJ)',''),
'(DF)',''),'(ES)',''),'(MS)',''),'(MT)',''),'(BA)',''),
'(PI)',''),'(AL)',''),'(TO)',''),'(PE)',''),'(PA)',''),
'(CE)',''),'(RN)',''),'(MA)',''),'(AP)',''),'(RR)',''),
'(RN)',''),'(AM)',''),'(AC)',''),'(XX)',''),'(EX)',''),
'(SE)',''),'(PB)',''),'(GO)',''),'(RO)',''))
Added space for readability(?).
The good news is that I don’t think Brazil will be adding any major cities that deserve their own acronym anytime soon. But by effectively hard-coding a list of viable abbreviations instead of using more advanced string splitting (or *gasp* regular expressions), or you know by actually normalizing the data correctly, they did a good job of making the code harder to maintain.
REPLACE REPLACE REPLACE REPLACE this code.
ProGet has you covered with security and access controls for your NuGet feeds. Find out more.