0
I have the following query in SQL Server, to return me a list of cities I need.
select IDCidade as "ID",
case UF when 'RS' then '1'
when 'SC' then '2'
when 'PR' then '3'
when 'SP' then '4'
when 'RJ' then '5'
when 'MG' then '6'
when 'ES' then '7'
when 'BA' then '8'
when 'MS' then '9'
when 'MT' then '10'
when 'GO' then '11'
when 'DF' then '12'
when 'TO' then '13'
when 'AM' then '14'
when 'AC' then '15'
when 'RO' then '16'
when 'RR' then '17'
when 'PA' then '18'
when 'AP' then '19'
when 'MA' then '20'
when 'PI' then '21'
when 'RN' then '22'
when 'CE' then '23'
when 'SE' then '24'
when 'AL' then '25'
when 'PB' then '26'
when 'PE' then '27'
else '28' end as "ESTADO",
case Nome when 'CidadeNome' then 'Não Informado'
else UPPER(LEFT(Nome,1))+LOWER(SUBSTRING(Nome,2,LEN(Nome))) end as "NOME"
from cidades
where IDCidade in ( select IDCidade from empresas )
However, this listing is showing me some values of duplicated cities, which were entered wrong in the bank. I want to know how to return the values of this query, without duplicate city names. I tried to use a distinct
in the field Name but he kept the same amount.
What is the correct way to do this query?
Are you sure there are repeated denominations for localities? Remember that in Brazil there are several homonymous localities (usually in different states).
– José Diz