Split Sql Row if Value of a Column is greater than 0

Fischerk12

So currently I have a table that has a bunch of fields and 3 cost fields (labor, Parts, Misc). What I want to do is have a the table split this up so that there is only one cost field that actually has data per row. Then have the other cost fields be blank. Example.

Name | Labor |Parts | Misc
test1  800    500     0
test2  0      500     0
test3  700    200     120

to 

Name | Labor |Parts | Misc

test1  800    0       0
test1  0      500     0
test2  0      500     0
test3  700    0       0
test3  0      200     0
test3  0      0     120

I am Fairly new to SQL work and I can't find a good solution to this. Any thoughts would be great.

Thanks

Robert

Try this way:

select Name,  Labor, 0 as Parts,0 as Misc
from Table 
where Labor > 0
union all
select Name,   0 as Labor, Parts,0 as Misc
from Table 
where Parts > 0
union all
select Name,  0 as Labor, 0 as Parts,Misc
from Table 
where Misc > 0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find column index where row value is greater than zero in R

From Dev

Output with value greater than 0

From Dev

UPDATE column if column is greater than a value

From Dev

SQL if row not present 0 else column value

From Dev

SUMIF Value is Greater Than Value in Previous Column

From Dev

How to scan a pandas dataframe for all values greater than something and returns row and column number corresponding to that value?

From Dev

How to scan a pandas dataframe for all values greater than something and returns row and column number corresponding to that value?

From Dev

Counting the number of columns greater than 0 for each row in SQL Server 2012

From Dev

Find minimum value greater than 0

From Dev

Getting minumum value but greater than 0

From Dev

Display Message box if value is greater than 0

From Dev

Pandas change column value if greater than len

From Dev

querying a collection with a value greater than 0 while keeping the current month whether the value is 0 or greater than 0

From Dev

SQL Join with duplicate row if value in column is more than 1

From Dev

Get the row if Column is having other than provided value in oracle SQL

From Dev

SQL Where clause use if value greater than

From Dev

Realm check if value of first column greater than value of second column

From Dev

Split a row based on a column value

From Dev

If any variable in a row is greater than a value, keep the row in R

From Dev

Create new column that merges column names greater than 0

From Dev

php - Split an associative array with value greater than some integer

From Dev

Select greater value than 0 if it exists, leave 0 if it is the only option

From Dev

Vb .net Error, No row in database greater than 0

From Dev

Postgresql: Join another column on the least value greater than left column

From Dev

How use Greater Than 0 (>0) within Case in Sql Server?

From Dev

Excel min value greater than x returns 0 if no value found?

From Dev

Excel min value greater than x returns 0 if no value found?

From Dev

only display value if input value is greater than 0

From Java

Highlight a cell if the value is greater than the value of the cell from the preceding column

Related Related

  1. 1

    Find column index where row value is greater than zero in R

  2. 2

    Output with value greater than 0

  3. 3

    UPDATE column if column is greater than a value

  4. 4

    SQL if row not present 0 else column value

  5. 5

    SUMIF Value is Greater Than Value in Previous Column

  6. 6

    How to scan a pandas dataframe for all values greater than something and returns row and column number corresponding to that value?

  7. 7

    How to scan a pandas dataframe for all values greater than something and returns row and column number corresponding to that value?

  8. 8

    Counting the number of columns greater than 0 for each row in SQL Server 2012

  9. 9

    Find minimum value greater than 0

  10. 10

    Getting minumum value but greater than 0

  11. 11

    Display Message box if value is greater than 0

  12. 12

    Pandas change column value if greater than len

  13. 13

    querying a collection with a value greater than 0 while keeping the current month whether the value is 0 or greater than 0

  14. 14

    SQL Join with duplicate row if value in column is more than 1

  15. 15

    Get the row if Column is having other than provided value in oracle SQL

  16. 16

    SQL Where clause use if value greater than

  17. 17

    Realm check if value of first column greater than value of second column

  18. 18

    Split a row based on a column value

  19. 19

    If any variable in a row is greater than a value, keep the row in R

  20. 20

    Create new column that merges column names greater than 0

  21. 21

    php - Split an associative array with value greater than some integer

  22. 22

    Select greater value than 0 if it exists, leave 0 if it is the only option

  23. 23

    Vb .net Error, No row in database greater than 0

  24. 24

    Postgresql: Join another column on the least value greater than left column

  25. 25

    How use Greater Than 0 (>0) within Case in Sql Server?

  26. 26

    Excel min value greater than x returns 0 if no value found?

  27. 27

    Excel min value greater than x returns 0 if no value found?

  28. 28

    only display value if input value is greater than 0

  29. 29

    Highlight a cell if the value is greater than the value of the cell from the preceding column

HotTag

Archive