Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi,

i have records in table like this:
id   v1    v2   v3
1  587     21   759   
2  230     4    495

now i want ouput like below:
id  v1       v2
1  587     21   
2  587     759
3  230     4
4  230     495



i am stuck here don't know what will be query for this.

p help me

thanks
Posted
Updated 24-Jul-12 2:55am
v2
Comments
Sandeep Mewara 24-Jul-12 9:13am    
How did ID field value incremented from just 1 & 2 to 1,2,3,4?

Try :
SQL
select id,v1,v2 from [table] order by id
 
Share this answer
 
Comments
Sandeep Mewara 24-Jul-12 9:14am    
I doubt this will do what OP is looking for!
Actually, incomplete/unclear question posted.
As you have described Input and output values

it is clear that you want v2 and v3 columns as row in resultant table

to get same output described in your question,
use query given below

SQL
select row_number() over(partition by id,v1 order by id,v1) as id,v1,v2 from
(
select id,v1,v2 from table
union all
select id,v1,v3 as v2 from table
) as a
order by id,v1


Happy Coding!
:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900