September 17, 2009 at 11:15 am
I have a field in table which contains comma delimited id values for each related record.
Now I want to find the records from main table with Ids not in this fields from related table.
all the ids are numeric in the main table and the related table has fields "splink" which contains comma delimited values of main table.
simple select with like
select * from maintable where id not in (select linkid from relatedtable )
does not work here
How do I go about it.
September 17, 2009 at 11:21 am
you might want to search for "split string function" on this site. There are many solutions available.
September 17, 2009 at 11:22 am
It would be very helpful if you point me to the exact link.
Rajesh
September 17, 2009 at 11:57 am
This link should help you further.
September 17, 2009 at 12:02 pm
LOL :laugh:
Really funny Lutz. I had not seen that site before. Guess Rajesh asked for it..:-)
September 17, 2009 at 12:10 pm
I have to say I am truly impressed Lutz, good job, I need to be able to do that.
Cheers,
J-F
September 17, 2009 at 12:13 pm
I have solved the problem by creating a new table which contains the id of related table and record for each id of main table. updated it in the trigger.
But this was possible because I had access to modify the tables.
September 17, 2009 at 12:15 pm
Once it a while it's required to point out that we're all volunteers who are willing to help. The link above is just one possible way to transfer the message. 😀
We're no online-{F1}-replacement nor charity consultants.
September 17, 2009 at 12:19 pm
I have been playing with split function but was not able to use it for fields directly from select command.
September 17, 2009 at 10:39 pm
lmu92 (9/17/2009)
This link should help you further.
Heh... not so funny, Lutz 😉 ... the very first article that shows up contains both a UDF and a While Loop. At least point him to an article that isn't going to kill him performance wise. :hehe:
--Jeff Moden
Change is inevitable... Change for the better is not.
September 17, 2009 at 10:48 pm
rajeshhalyal (9/17/2009)
I have a field in table which contains comma delimited id values for each related record.Now I want to find the records from main table with Ids not in this fields from related table.
all the ids are numeric in the main table and the related table has fields "splink" which contains comma delimited values of main table.
simple select with like
select * from maintable where id not in (select linkid from relatedtable )
does not work here
How do I go about it.
Please see the following article. It shows not only how to avoid certain While Loops, but it also shows how to do splits without them. There are several other methods (only one or two are a bit faster) but this should suit you just fine.
http://www.sqlservercentral.com/articles/T-SQL/62867/
There's also a useful follow up to the article here...
http://www.sqlservercentral.com/articles/T-SQL/63003/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply