Dear all,
I have two table, both table have a col which stored the data in CSV format, ie "ab , bc, de", etc
I would like to select the item where "any one item" in first table is same as "any one item" on second table.
I have alread have the private CSV function which can convert the string and return as table. However, I find i cannot do it like this
select .... where dbo.CSVfunction(tableA.colA)
Thx
//CSV function
declare @.separator char(1)
set @.separator = ','
declare @.separator_position int
declare @.array_value varchar(1000)
set @.array = @.array + ','
while patindex('%,%' , @.array) <> 0
begin
select @.separator_position = patindex('%,%' , @.array)
select @.array_value = left(@.array, @.separator_position - 1)
select @.array_value = RTrim(@.array_value)
select @.array_value = LTrim(@.array_value)
Insert @.StringTable
Values (Cast(@.array_value as varchar(50)))
select @.array = stuff(@.array, 1, @.separator_position, '')
end
re @.separator char(1)
set @.separator = ','
declare @.separator_position int
declare @.array_value varchar(1000)
set @.array = @.array + ','
while patindex('%,%' , @.array) <> 0
begin
select @.separator_position = patindex('%,%' , @.array)
select @.array_value = left(@.array, @.separator_position - 1)
select @.array_value = RTrim(@.array_value)
select @.array_value = LTrim(@.array_value)
Insert @.StringTable
Values (Cast(@.array_value as varchar(50)))
select @.array = stuff(@.array, 1, @.separator_position, '')
end
No comments:
Post a Comment