April 7, 2006 at 12:21 am
i have a table which i would like to transform its columns into rows
Thanks in Advns
April 7, 2006 at 2:06 am
------------
When you 've got a hammer, everything starts to look like a nail...
April 7, 2006 at 4:25 am
Can you do lilke this move the data to excel sheet, copy all data and while pasting select paste special and select transpose..
April 7, 2006 at 5:30 am
select col1 from table1
union all
select col2 from table1
union all
select col3 from table1
April 7, 2006 at 7:07 am
KH, I don't think that will quite do what Parmesh wants. That union won't transpose the table. It will just concatenate all the information into one long column.
Parmesh, your problem is, essentially, not solvable in T-SQL, simply because rows and columns are radically different things, that obey very different rules. However, there are some specific cases where it is needed. But, the solution depends on the case.
If this is an occasional need, exporting it to Excel and transposing is the easiest solution.
If you need a cross-tab style query to do fairly simple analysis, you can accomplish it with CASE statements. I can elaborate if that fits your needs.
If you want to do more complicated analysis, look into OLAP cubes.
If none of these fit your needs, then you are probably either looking at the original problem from the wrong angle, or you are working with poor table design.
April 8, 2006 at 12:31 am
ty Marshall Smith. i have used C#.Net for this Problem. i have got the result.
Thankyou very much
parmesh
April 8, 2006 at 9:50 am
KH did it right... if you expand upon the example KH provided, it works great, is nasty fast, and does not require a trip to the app.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 10, 2006 at 6:06 am
OK, Jeff, how did KH do it right?
Suppose the table is:
A 1 *
B 2 @
C 3 #
As I read it, Parmesh wanted:
A B C
1 2 3
* @ #
KH's solution produces:
A
B
C
1
2
3
*
@
#
Which is not the same thing at all. Even when expanded upon. Is there something I'm missing?
April 10, 2006 at 5:28 pm
Guess I read it differently, Marshall... I didn't read the original request as a full transposition based on what some folks have asked for in the past... Not enough coffee
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply