-2

In simple terms the table (t1) looks like this:

id     hours    dollars
-----------------------
abc     4         40

I'd like to get results from the table that looks like this:

abcHours      4      0
abcDollars    0      40

Thanks

Dale K
  • 25,246
  • 15
  • 42
  • 71
Green
  • 87
  • 7

2 Answers2

1

You can unpivot with cross apply:

select x.*
from mytable t
cross apply (values 
    (concat(id, 'Hours'  ), hours, 0      ), 
    (concat(id, 'Dollars'), 0,     dollars)
) as x(newid, hours, dollars)
GMB
  • 216,147
  • 25
  • 84
  • 135
0

You may try simple query, using operator Union:

Select  'abcHours' as  abcHour, hours as Hour, 0 as dollar
Union all
Select  'abcDollars', 0, dollars
Olga Romantsova
  • 1,096
  • 1
  • 6
  • 8