469,086 Members | 1,133 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,086 developers. It's quick & easy.

How to convert columns to rows

4
Hi,

I have some procedures with dynamic sql(generic procedure for different tables) to do the convert columns to rows but have performance issue. Is there a better way like a single SQL that can solve my problem, thanks!!!

Table A(total 20 columns)
Col1 Col2 Col3 Col4 ... Col20

Table B(total 10 columns)
Col1 Col2 Col3 Col4... Col10

My procedure like this(pseudo code)
---------------------------------
for loop(table) <-- Loop Table A & B
for loop(loop records in the table) <-- Records in Table A & Table B
for loop(loop columns in a table) <-- No. of columns in Table
insert into a new_table(ColName, ColValue, current timestamp)
end for
end for
end for
Dec 21 '12 #1
1 5533
Rabbit
12,516 Expert Mod 8TB
Use a UNION query.
Dec 21 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by John Spiegel | last post: by
3 posts views Thread by helpful sql | last post: by
9 posts views Thread by Classic-Car-World Ltd | last post: by
1 post views Thread by lenygold via DBMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.