February 12, 2012 at 10:05 pm
Hi All,
Recently i came up with this business requirement where i have to generate columns dynamically according to the duplicate data in the rows.
This is the example scenario:
Table structure
Pk,fkPk,fkPk,fkPk,fkPk,fkPkValue1Value 2</tr?
A1A2A3A4A51xxyy
A1A2A3A4A52xxxyyy
A1A2A3A4A53ab
A1B2A3A4A54aabb
B1A2A3A4A55aaabbb
B1B2B3B4B56de
B1B2B3B4B57ddee
B1B3C3B4B58dddeee
Now I have to write a stored procedure which gives output like below:
A1A2A3A4A5xxyyxxxyyyab
A1B2A3A4A5aabb
B1A2A3A4A5aaabbb
B1B2B3B4B5deddee
B1B2C3B4B5dddeee
Please help me out
February 13, 2012 at 8:07 am
http://www.sqlservercentral.com/articles/T-SQL/63681/%5B/url%5D
Make sure you read and then follow along to the second article about how to make this dynamic.
_______________________________________________________________
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 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply