在我的San_Imovel
桌子上,我有很多财产,我想知道是否有一些重复(同一地址中的财产)。所以,我得到了一个地址,我确信在同一个地址中有很多属性,但在我的CASE WHEN EXIST
返回 0 中。
有人可以帮助我吗?
如果我单独运行,在我返回 47 行的SELECT
语句中。CASE WHEN EXITS
询问
declare @cityName as varchar(100)
declare @neighborName as varchar(100)
declare @zipcode as varchar(8)
declare @complement as varchar(100)
declare @street as varchar(100)
declare @number as varchar(6)
set @cityName = 'Sao Paulo'
set @neighborName = 'Tupi'
set @zipcode = '31840050'
set @complement = '123'
set @street = 'Furquim werneck'
set @number = '5989828'
;WITH cte
AS (
SELECT City_Id, State_Id, CityName
FROM City
WHERE (CityName COLLATE SQL_Latin1_General_CP1_CI_AI) LIKE '' + @cityName + ''
)
select
CASE
WHEN EXISTS (
SELECT San_Imovel.Imovel_Id
FROM San_Imovel
WHERE San_Imovel.Number = @number
AND San_Imovel.ZipCode = @zipcode
AND San_Imovel.Complement = @complement
AND San_Imovel.Street = @street
AND San_Imovel.City_Id = cte.City_Id
)
THEN 1
ELSE 0
END AS ExistDuplicate
from cte
数据样本
Imovel_Id bigint
Number int
Complement varchar
Street varchar
City_Id int
Zipcode varchar
Imovel_Id Number Complement Street City_Id ZipCode
433669 5989828 123 Furquim Werneck 2754 31840050
433670 5989828 123 Furquim Werneck 2754 31840050
433671 5989828 123 Furquim Werneck 2754 31840050