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 |
xclaim
Starting Member
8 Posts |
Posted - 2013-06-21 : 10:54:51
|
here is my sample datagroup1 list1;list2;list3;list10group2 list4;list5;list1this is the output i needgroup1 list1group1 list2group1 list3group1 list10group2 list4group2 list5group2 list1please help |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-06-21 : 11:18:58
|
Use unpivot. Would be something like this: SELECT * FROMtblUNPIVOT (Groups FOR Lists IN ([listcol1],[listcol2],[listscol3])) u |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
xclaim
Starting Member
8 Posts |
Posted - 2013-06-21 : 20:21:10
|
great this works : I modified the function though since i rant out of varcharthank you thank you thank youhere is the modified version : It works great"/****** Object: UserDefinedFunction [dbo].[ParseValues] Script Date: 6/21/2013 8:18:34 PM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER FUNCTION [dbo].[ParseValues](@String varchar(8000), @Delimiter varchar(10) )RETURNS @RESULTS TABLE (ID int identity(1,1), Val varchar(8000))ASBEGINDECLARE @Value varchar(8000)WHILE @String is not nullBEGINSELECT @Value=CASE WHEN PATINDEX('%'+@Delimiter+'%',@String) >0 THEN LEFT(@String,PATINDEX('%'+@Delimiter+'%',@String)-1) ELSE @String END, @String=CASE WHEN PATINDEX('%'+@Delimiter+'%',@String) >0 THEN SUBSTRING(@String,PATINDEX('%'+@Delimiter+'%',@String)+LEN(@Delimiter),LEN(@String)) ELSE NULL ENDINSERT INTO @RESULTS (Val)SELECT @ValueENDRETURNEND"quote: Originally posted by visakh16
SELECT t.group,f.ValFROM table tCROSS APPLY dbo.ParseValues(t.listfield,';')f ParseValues can be found herehttp://visakhm.blogspot.in/2010/02/parsing-delimited-string.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-22 : 02:24:41
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|