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)
 Insert value if not available

Author  Topic 

baburk
Posting Yak Master

108 Posts

Posted - 2008-11-19 : 01:41:38
Hi,

Here @Tags contains Babu, Saravanan. If 'Saravanan' is in the table insert only 'Babu'.

From the below query how can I able to pass the value for the Tag

SET ItemId = 10
SET @Tags = 'Babu,Saravanan'

INSERT INTO (ItemId, Tag) dbo.ItemTags VALUES(@ItemId, ? )
WHERE ','+@Tags+',' NOT LIKE '%,'+ItemTags.Tag+',%'

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-19 : 02:04:58
[code]INSERT INTO dbo.ItemTags (ItemId, Tag)
SELECT @ItemId, Val
FROM dbo.ParseValues(@Tags,',') f
LEFT JOIN dbo.ItemTags t
ON f.Val=t.Tag
WHERE t.Tag IS NULL[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-19 : 02:06:01
ParseValues can be found here

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113563
Go to Top of Page

baburk
Posting Yak Master

108 Posts

Posted - 2008-11-19 : 02:26:17
quote:
Originally posted by visakh16

ParseValues can be found here

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113563



Thanks for your help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-19 : 03:13:50
Welcome
Go to Top of Page
   

- Advertisement -