Reputation: 59
I need to change table rows and columns using sql, without using any pointer in Sqlserver or any other function. ex:
I have these data on table:
h1 | h2 | h3 | date
1 2 3 d1
4 5 6 D2
I want to replace them and convert to this:
h value | date
1 d1
2 d1
3 d1
4 D2
5 D2
6 D2
Any solution?
Upvotes: 0
Views: 61
Reputation: 1726
SELECT h_value, date
FROM
(
SELECT h1 AS h_value, date
FROM your_table
UNION
SELECT h2 AS h_value, date
FROM your_table
UNION
SELECT h3 AS h_value, date
FROM your_table
)
ORDER BY h_value
Upvotes: 1
Reputation: 1656
This should work:
SELECT h1 AS h_value, date FROM [table] UNION ALL
SELECT h2 AS h_value, date FROM [table] UNION ALL
SELECT h3 AS h_value, date FROM [table]
Upvotes: 1
Reputation: 4630
Something like
create table table_new as
select h1 as "h value",date from table
union all
select h2,date from table
union all
select h3,date from table
Upvotes: 0