| Author |
Topic |
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-08 : 05:49:48
|
Sample dataDROP TABLE #testTableCREATE TABLE #testTable ( id int, Data varchar(100) )INSERT INTO #testTable SELECT 1, '12345'UNION ALLSELECT 2, 'Microsoft Windows XP Professional'UNION ALLSELECT 3, 'Service Pack 3'UNION ALLSELECT 4, '5/8/2010 0:4:37'UNION ALLSELECT 5, 'b4b9471c-1a5e-4d9c-94ef-84b00592946a.100'SELECT * FROM #testTable I have a resultset I want these rows of id as column and data as value of the columns column names will be RegID, OS, SP, Date, UpdateID for 1, 2, 3, 4, 5 respectivelyHow can i do it is the part of a large process.Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-08 : 06:17:10
|
| whats the column by which you group these rows? what designates which rows should be merged as a single record?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-08 : 06:35:47
|
| The resultset will have single entry for each id there will be no grouping.as this result set is derived from some queryVaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-08 : 06:49:18
|
| consider sample dataINSERT INTO #testTable SELECT 1, '12345'UNION ALLSELECT 2, 'Microsoft Windows XP Professional'UNION ALLSELECT 3, 'Service Pack 3'UNION ALLSELECT 4, '5/8/2010 0:4:37'UNION ALLSELECT 5, 'b4b9471c-1a5e-4d9c-94ef-84b00592946a.100'UNION ALLSELECT 6, '21324'UNION ALLSELECT 7, 'Microsoft Windows 2000'UNION ALLSELECT 8, 'Service Pack 4'then how will you determine which all should come in a row?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-08 : 07:04:56
|
| Might be i was not able to clear the thingbut the situation is like I will have one string in a loop i m spliting that string and getting fixed number of rows every time by my split functionSELECT id, Data From Split(@String, ',')Now i m getting some resultset but now i want data as column values not the row values.I hope now i m clear to you??Please help me out..Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-08 : 07:49:20
|
| Guys i got the solution..SELECT * FROM (SELECT CASE IDWHEN 1 THEN 'RegID'WHEN 2 THEN 'OS'WHEN 3 THEN 'SP'WHEN 4 THEN 'Date'WHEN 5 THEN 'UpdateID'END AS Col,Data FROM #TestTable) AS src PIVOT (MAX(Data) FOR Col IN ([RegID],[OS],[SP],[Date],[UpdateID])) AS pvtVaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-08 : 10:34:28
|
| does you always have only one set of values?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-05-10 : 02:14:52
|
Yes as I am separating a long string into multiple string and that each string having one set of values that which i m getting after again saperating values from each string.i m getting which is like the sample data.In First string strings are separated by #@@# and second string is seperated by RegID.quote: Originally posted by visakh16 does you always have only one set of values?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-10 : 13:36:33
|
| i cant really understand reason of doing all this!------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|