Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help SP with delimited string

Author  Topic 

soppie
Starting Member

3 Posts

Posted - 2011-05-27 : 05:16:36
Hi,

thought it was time to ask some help:

I need a SP which gets 2 separate delimited strings (dsA and dsB).
In table A I have a field which holds dsA like ,3,67,240,2,8,
In table B I have a field which holds dsB like ,240,23,3,9,214,

Now I need to check if a value in dsA exists in dsB.
So in my example I have 2 matches: 3 and 240.
How can I query for the 2 matches with a SP in SQL2005?

Thx!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-27 : 07:28:15
split the strings into tables using ParseValues function that you can find on this site, and then inner join the tables.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

soppie
Starting Member

3 Posts

Posted - 2011-05-28 : 02:59:09
ParseValues is limited (as far as I know) to 4 parts of a string
Is it possible to do without (temp) tables.?
The SP is going to be used a lot in my app and the strings wil get bigger along with time.


Thx!
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-05-28 : 07:13:52
If efficiency is a consideration, take a look at this article - in particular, the code in Fig. 21. You should be able to copy the code, run it to install and then use it to split the string into its constituents. Then you can follow Jim's suggestion. http://www.sqlservercentral.com/articles/Tally+Table/72993/

If you have any control over it, you may want to redesign the manner in which the data is stored. Instead of appending new data to the comma-separated string, if you can store the data in a normalized table, that would make it querying for this type of information much much easier.
Go to Top of Page
   

- Advertisement -