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.
Author |
Topic |
emmim44
Yak Posting Veteran
65 Posts |
Posted - 2012-06-21 : 05:54:36
|
Hi there,I need to compare a list values with a db column.Example : list ='12,5,6,8' and I need to know which of these values doesnt exist in db column values. How would I do that?DbColumnKeys11010010001001100210031004 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-06-21 : 06:08:14
|
You'll need to split the list into values in a table.Seehttp://www.simple-talk.com/sql/t-sql-programming/sql-server-2005-common-table-expressions/;with csvtbl(i,j)as(select i=1, j=charindex(',',@s+',')union allselect i=j+1, j=charindex(',',@s+',',j+1) from csvtblwhere charindex(',',@s+',',j+1) <> 0) ,cte as(select val = substring(@s,i,j-i)from csvtbl )select *from ctewhere val not in (select DbColumnKeys from tbl)where ==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
emmim44
Yak Posting Veteran
65 Posts |
Posted - 2012-06-21 : 07:07:36
|
good one...Thank you v m |
 |
|
|
|
|
|
|