Skip to content
Advertisement

SQL Server 2008 R2 split one row of results into two rows

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

Advertisement

Answer

You may try simple query, using operator Union:

Select  'abcHours' as  abcHour, hours as Hour, 0 as dollar
Union all
Select  'abcDollars', 0, dollars
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement