34,593
社区成员
发帖
与我相关
我的任务
分享
UPDATE house
SET house.HouseType = a.HouseType,
house.DataType = a.DataType,
house.ProjectName = a.ProjectName ,
house.Area = a.Area
FROM (
select h.Phone,
ISNULL(ht.HouseType,case when charindex(ht.HouseType, h.HouseType)=0 then h.HouseType+','+ht.HouseType
else h.HouseType end) HouseType,
ISNULL(ht.DataType, case when charindex(ht.DataType, h.DataType)=0 then h.DataType+','+ht.DataType
else h.DataType end) DataType,
ISNULL(ht.ProjectName,case when charindex(ht.ProjectName , h.ProjectName )=0 then h.ProjectName +','+ht.ProjectName
else h.ProjectName end) ProjectName,
ISNULL(ht.Area, case when charindex(ht.Area, h.Area)=0 then h.Area+','+ht.Area
else h.Area end) Area
from House h
inner join HouseTemp ht on h.Phone = ht.Phone
) a INNER JOIN
house b ON a.Phone = b.Phone
insert into #temp select *,row_number() over(patition by 电话) as rn from HouseTemp
然后找出#temp中rn最大的赋值给整型变量@num,定义一个变量@i起始值为1再用下面的语句
while @i<=@num
begin
UPDATE house
SET house.户型 = a.户型,
house.数据类型 = a.数据类型,
house.楼盘名称 = a.楼盘名称,
house.区域 = a.区域
FROM (
select h.电话,ISNULL(ht.户型,case when charindex(ht.户型, h.户型)=0 then h.户型+','+ht.户型 else h.户型 end) 户型,
ISNULL(ht.户型,case when charindex(ht.数据类型, h.数据类型)=0 then h.数据类型+','+ht.数据类型 else h.数据类型 end) 数据类型,
ISNULL(ht.户型,case when charindex(ht.楼盘名称, h.楼盘名称)=0 then h.楼盘名称+','+ht.楼盘名称 else h.楼盘名称 end) 数据类型,
ISNULL(ht.户型,case when charindex(ht.时间, h.时间)=0 then h.时间+','+ht.时间 else h.时间 end) 时间,
ISNULL(ht.户型,case when charindex(ht.区域, h.区域)=0 then h.区域+','+ht.区域 else h.区域 end) 区域
from House h
inner join #temp ht on h.电话 = ht.电话
where rn = @i
) a INNER JOIN
house b ON a.电话 = b.电话
set @i=@i+1
end
UPDATE house
SET house.户型 = a.户型,
house.数据类型 = a.数据类型,
house.楼盘名称 = a.楼盘名称,
house.区域 = a.区域
FROM (
select h.电话,ISNULL(ht.户型,case when charindex(ht.户型, h.户型)=0 then h.户型+','+ht.户型 else h.户型 end) 户型,
ISNULL(ht.户型,case when charindex(ht.数据类型, h.数据类型)=0 then h.数据类型+','+ht.数据类型 else h.数据类型 end) 数据类型,
ISNULL(ht.户型,case when charindex(ht.楼盘名称, h.楼盘名称)=0 then h.楼盘名称+','+ht.楼盘名称 else h.楼盘名称 end) 数据类型,
ISNULL(ht.户型,case when charindex(ht.时间, h.时间)=0 then h.时间+','+ht.时间 else h.时间 end) 时间,
ISNULL(ht.户型,case when charindex(ht.区域, h.区域)=0 then h.区域+','+ht.区域 else h.区域 end) 区域
from House h
inner join HouseTemp ht on h.电话 = ht.电话
) a INNER JOIN
house b ON a.电话 = b.电话
UPDATE house
SET house.户型 = a.户型,
house.数据类型 = a.数据类型,
house.楼盘名称 = a.楼盘名称,
house.区域 = a.区域
FROM (
select h.电话,case when charindex(ht.户型, h.户型)=0 then h.户型+','+ht.户型 else h.户型 end 户型,
case when charindex(ht.数据类型, h.数据类型)=0 then h.数据类型+','+ht.数据类型 else h.数据类型 end 数据类型,
case when charindex(ht.楼盘名称, h.楼盘名称)=0 then h.楼盘名称+','+ht.楼盘名称 else h.楼盘名称 end 数据类型,
case when charindex(ht.时间, h.时间)=0 then h.时间+','+ht.时间 else h.时间 end 时间,
case when charindex(ht.区域, h.区域)=0 then h.区域+','+ht.区域 else h.区域 end 区域
from House h
inner join HouseTemp ht on h.电话 = ht.电话
) a INNER JOIN
house b ON a.电话 = b.电话