-2

こんにちは、以下のクエリを使用しています。

Create proc [dbo].[usp_getPropertyByWord]  
(@Description nvarchar(200))  
as  

set @Description=replace(@Description,'   ',' ')  
set @Description=replace(@Description,'  ',' ') 

create table #temp(name varchar(100)) 
insert into #temp valueS(@Description)
insert into #temp 
SELECT word FROM dbo.splitStringChars(@Description,' ',',')
delete #temp where name in('',' ',',')

create table #temp1(property_id int,property_number nvarchar(15),name nvarchar(500),short_desciption nvarchar(2000),description nvarchar(4000),address1 nvarchar(200),address2 nvarchar(200),city nvarchar(50),locality nvarchar(100),zip nvarchar(8)) 
insert into #temp1(property_id,property_number,name ,short_desciption,description,address1,address2,city,locality,zip)
SELECT distinct(p.property_id),p.property_number,p.name,p.short_description,p.description,ta.address1,ta.address2,
tc.city_name,cl.City_Locality_Name,ta.zip
FROM tbl_property p  
INNER JOIN 
tbl_PropertyAddress ta on ta.property_id=p.property_id
inner join tbl_City tc on ta.city=tc.city_id
inner join  tbl_City_Locality cl on cl.City_id=tc.city_id
inner join
(SELECT distinct(name) FROM #temp) B  
ON (p.name=@Description or p.name LIKE '%' + B.name + '%' or p.short_description like '%' + B.name + '%' or p.description like '%' + B.name + '%'
or ta.address1 LIKE '%' + B.name + '%' or ta.address2 LIKE '%' + B.name + '%' or tc.City_Name LIKE '%' + B.name + '%')  
where  NOT EXISTS(select t.* from #temp1 t where t.property_id=p.property_id and t.property_number=p.property_number and t.name=p.name and t.short_desciption=p.short_description and t.description=p.description and t.address1=ta.address1 and t.address2=ta.address2 and t.city=tc.City_Name and t.locality=cl.City_Locality_Name and t.zip=ta.zip)


  delete  #temp
  select  *  from #temp1
GO

@Description に" 'hyderbad hyd,hgf , hyds '"を指定すると、16000 レコードが取得されますが、テーブルには 130 レコードしかありません。

splitStringChars 関数から値を取得しています

hyderbad     
hyd    
hgf    
hyds  

これはどのように解決できますか?

4

1 に答える 1

0

TSQLを知っていますか?

Create proc [dbo].[usp_getPropertyByWord]  
(@Description nvarchar(200))  
as  

set @Description=replace(@Description,'   ',' ')  
set @Description=replace(@Description,'  ',' ') 

create table #temp(name varchar(100)) 
insert into #temp valueS(@Description)
insert into #temp 
SELECT word FROM dbo.splitStringChars(@Description,' ',',')
delete #temp where name in('',' ',',')


SELECT p.property_id,p.property_number,p.name,p.short_description,p.description
-- ,ta.address1,ta.address2,tc.city_name,cl.City_Locality_Name,ta.zip
FROM tbl_property p  
-- INNER JOIN 
--tbl_PropertyAddress ta on ta.property_id=p.property_id
--inner join tbl_City tc on ta.city=tc.city_id
--inner join  tbl_City_Locality cl on cl.City_id=tc.city_id
inner join
(SELECT distinct(name) FROM #temp) B  
ON (p.name=@Description or p.name LIKE '%' + B.name + '%' or p.short_description like '%' + B.name + '%' or p.description like '%' + B.name + '%'
-- or ta.address1 LIKE '%' + B.name + '%' or ta.address2 LIKE '%' + B.name + '%' 
-- or tc.City_Name LIKE '%' + B.name + '%'
)  
where  NOT EXISTS(select t.* from #temp1 t where t.property_id=p.property_id and t.property_number=p.property_number and t.name=p.name and t.short_desciption=p.short_description and t.description=p.description 
-- and t.address1=ta.address1 and t.address2=ta.address2 and t.city=tc.City_Name and t.locality=cl.City_Locality_Name and t.zip=ta.zip
)
于 2012-05-17T22:09:18.200 に答える