date - SQL SERVER - CHANGE COLUMN NAME TO VALUE -
date - SQL SERVER - CHANGE COLUMN NAME TO VALUE -
i have table this:
id | date 1 | date 2 | date 3 1 | 2014-08-01 | 2014-08-02 | 2014-08-03
and need output this:
id | date field name | date value 1 | date 1 | 2014-08-01 1 | date 2 | 2014-08-02 1 | date 3 | 2014-08-03
have tried dynamic unpivoting unions seems messy. there best practice way of doing this?
i think unpivot
best practice here. don't find messy much confusing, maybe because don't reach often. give results you're looking for:
select id, [date field name], [date value] mytable unpivot ([date value] [date field name] in ([date 1], [date 2], [date 3])) x
sql-server date
Comments
Post a Comment