March 29, 2013 at 9:58 am
This current table has to be converted to the @temp_out
Order would be like this Proc --> Type --> Individual task for that type
the order of the @temp_out task col is defined like Order by type is base on the seq col then the each Type will have the list of task below it
/*Current Table*/
Declare @temp Table ([Proc] INT,Seq INT,Type VARCHAR(2),Task VARCHAR(20))
INSERT INTO @TEMP
SELECT '1','1','a1','this is ' UNION ALL
SELECT '1','2','b2','supposed ' UNION ALL
SELECT '2','1','a1','to ' UNION ALL
SELECT '2','2','b2','be a ' UNION ALL
SELECT '2','3','c3','test db' UNION ALL
SELECT '2','4','c3','thank you'
SELECT * FROM @TEMP
/*Desired Table */
Declare @temp_out Table ([Proc] INT,Seq INT,Task VARCHAR(20))
INSERT INTO @temp_out
select '1','1','a1' union
select '1','1','this is ' union
select '1','2','b2' union
select '1','2','supposed ' union
select '2','1','a1' union
select '2','1','to ' union
select '2','2','b2' union
select '2','2','be a ' union
select '2','3','c3' union
select '2','3','test db' union
select '2','3','thank you'
SELECT * FROM @temp_out
March 29, 2013 at 10:08 am
Please don't post duplicate threads. The answer that Lowell gave you in the other thread is exactly the way to do this.
Please direct all replies here. http://www.sqlservercentral.com/Forums/Topic1436978-391-1.aspx
_______________________________________________________________
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/
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy