Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hello Friends, I have a comma separated list of integers and a table named "Pages" that contains 3 columns 1. pageId2. Name3. fk_topic( of type integer ) ( comma separated list actually contains the fk_topic)Now my requirement is i wanted two columns "Topic" and "PageId".For example:comma seperated list contains: 45,55,98Pages table data:pageId-----Name-----fk_topic1----------abc------452----------abc------453----------abc------454----------abc------555----------abc------556----------abc------557----------abc------558----------abc------989----------abc------98OUTPUT:TOPIC--------PAGEID45-----------145-----------245-----------355-----------455-----------555-----------655-----------798-----------898-----------9THANKS
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2009-07-27 : 11:09:00
make use of CSVTable or fnParseListKH[spoiler]Time is always against us[/spoiler]
amodi
Yak Posting Veteran
83 Posts
Posted - 2009-07-27 : 11:27:36
Can anybody post the sample query?Thanks.
amodi
Yak Posting Veteran
83 Posts
Posted - 2009-07-27 : 13:11:57
Its Urgent, please post a sample query
bklr
Master Smack Fu Yak Hacker
1693 Posts
Posted - 2009-07-28 : 02:12:29
try like this
declare @str1 table( str1 varchar(64))insert into @str1 select 'M001111,M001222,M001333'SELECT replace(SUBSTRING(str1,charindex(',',str1,v.number),abs(charindex(',',str1,charindex(',',str1,v.number)+1)-charindex(',',str1,v.number))),',','')as valueFROM @str1 sINNER JOIN master..spt_values AS v ON v.Type = 'P' AND v.number > 0 AND v.number <= len(str1) AND substring(',' + str1, v.number, 1) = ','