SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 compare list values with with db ms sql 2008
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

emmim44
Yak Posting Veteran

65 Posts

Posted - 06/21/2012 :  05:54:36  Show Profile  Reply with Quote
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?


DbColumnKeys

1

10

100

1000

1001

1002

1003

1004

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/21/2012 :  06:08:14  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
You'll need to split the list into values in a table.
See
http://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 all
select i=j+1, j=charindex(',',@s+',',j+1) from csvtbl
where charindex(',',@s+',',j+1) <> 0
) ,
cte as
(
select val = substring(@s,i,j-i)
from csvtbl
)
select *
from cte
where 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.
Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 06/21/2012 :  07:07:36  Show Profile  Reply with Quote
good one...Thank you v m
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000