September 18, 2013 at 1:07 pm
I have a table as follows
col1 col2 col3 col4 col5
A 11:30 13:30 15 11.30,11.45,12.00,12.15,12.30,12.45,13.00,13.15,13.30
i need the following output
A 11.30
A 11.45
A 12.00
A 12.15
A 12.30
A 12.45
A 13.00
A 13.15
A 13.30
earlier help is highly appreciated
September 18, 2013 at 1:41 pm
two links for you to look at
http://codebetter.com/raymondlewallen/2005/10/26/quick-t-sql-to-parse-a-delimited-string/
and
http://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
Dan
If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.
September 18, 2013 at 2:27 pm
kalikoi (9/18/2013)
I have a table as followscol1 col2 col3 col4 col5
A 11:30 13:30 15 11.30,11.45,12.00,12.15,12.30,12.45,13.00,13.15,13.30
i need the following output
A 11.30
A 11.45
A 12.00
A 12.15
A 12.30
A 12.45
A 13.00
A 13.15
A 13.30
earlier help is highly appreciated
It is nearly impossible to determine what is what from this. Please post ddl (create table statements) and sample data (insert statements).
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 18, 2013 at 2:28 pm
Dan.Humphries (9/18/2013)
two links for you to look athttp://codebetter.com/raymondlewallen/2005/10/26/quick-t-sql-to-parse-a-delimited-string/
I would recommend steering well away from this type of splitter. They perform acceptably for very small datasets, of course it is still a scalar function so the versatility of this is limited. You should take a look at the link in my signature about splitting strings. It is a much better approach than looping.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 18, 2013 at 2:35 pm
Looking at your original post again I think that Col2, Col3 and Col4 are just noise to the problem? All that really matters here is Col1 and Col5.
Here is an example of what I mean about posting consumable ddl and sample data.
create table #Something
(
Col1 char(1),
col2 char(5),
Col3 char(5),
Col4 int,
Col5 varchar(100)
)
insert #Something
select 'A', '11:30', '13:30', 15, '11.30,11.45,12.00,12.15,12.30,12.45,13.00,13.15,13.30'
To get this data we just need to split the value in Col5. This is easily done using the DelimitedSplit8K function. You can learn more about that function (and find the code for it) by following the link in my signature about splitting strings.
select Col1, x.Item as Col5Values
from #Something
cross apply dbo.DelimitedSplit8K(Col5, ',') x
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 18, 2013 at 2:55 pm
This post looks really related to this other
http://www.sqlservercentral.com/Forums/Topic1495877-391-1.aspx
Is it really about different things? or are you deciphering my code?
September 18, 2013 at 3:26 pm
Dan.Humphries (9/18/2013)
two links for you to look athttp://codebetter.com/raymondlewallen/2005/10/26/quick-t-sql-to-parse-a-delimited-string/
Just to reinforce what Sean stated, if you have a splitter function with a WHILE loop or the word BEGIN in it, it should be avoided even if you're "just doing something small".
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply