Temporary table | string declare @str1 varchar (MB), @str2 varchar (m), @str3 varchar (MB), @str varchar (500)
Set @str1 = ' AADA,BBBF,CCC, '
Set @str2 = ' DDD,AAAAAA,FDSA '
Set @str3 = ' vvvvvv,aaabbbb '
Set @str = ' Fds,bbbf,eee,ddd,fff,hhhfg,dddde '
Right now:
Split the @str1 into AADA,BBBF,CCC three elements, where BBBF appeared in @str.
Split the @str2 into DDD,AAAAAA,FDSA three elements, in which DDD also appeared in @str.
Split the @str3 into VVVVVV,AAABBBB two elements, but no elements appeared in @str.
How can I use the program to achieve such a result
Actually, the real problem is this.
I have a data table with a field in it ClassID
One of the records of the data, such as: AADA,BBBF,CCC
Now to get such a result set, the ClassID will be split in accordance with the above split, the data obtained, in the @str (@str is a parameter from the outside) find out, how can I do?
---------------------------------------------------------------
DECLARE @str varchar (500)
Set @str = ' Fds,bbbf,eee,ddd,fff,hhhfg,dddde '
CREATE table your table (ClassID varchar (100))
Insert your table values (' AADA,BBBF,CCC ')
Insert your table values (' DDD,AAAAAA,FDSA ')
Insert your table values (' VVVVVV,AAABBBB ')
SELECT * from your table where exists (select 1 from #临时表 where ', ' + your table. classid+ ', ' like '%, ' +a+ ',% ')
Go
drop table your table, #临时表
---------------------------------------------------------------
CREATE TABLE #t (
ID varchar (10))
DECLARE @str varchar (300)
Set @str = ' Fds,bbbf,eee,ddd,fff,hhhfg,dddde '
DECLARE @i int
DECLARE @len int
Set @i = 1
Set @str = ' Fds,bbbf,eee,ddd,fff,hhhfg,dddde ' + ', '
While @i < Len (@str)
Begin
Insert #t Select substring (@str, @i,charindex (",", @str, @i)-@i)
Set @i = charindex (', ', @str, @i) +1
End
SELECT * FROM datasheet A, #t B where CHARINDEX (b.id, A.classid) > 0
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.