How to split row into two rows in MS SQL

Ilya Trifonov

I get a row, which contains non-zero values in two columns: FixHours and AddHours:

FixHours | AddHours | CalculatedValue
---------+----------+----------------
     0,5 |      1,5 |            16.5

How can I split it into two rows such as:

FixHours | AddHours | CalculatedValue
---------+----------+----------------
     0,5 |        0 |            16.5
       0 |      1,5 |            16.5

I have had an idea to find that row and artificially make a second row using the union operator. But I have many rows with values in two columns at the same time. Any ideas?

Zohar Peled

Assuming I understand your question correctly, I think something like this is what you are looking for:

SELECT FixHours, AddHours, CalculatedValue
FROM tbl
WHERE FixHours = 0
OR AddHours = 0

UNION

SELECT FixHours, 0, CalculatedValue
FROM tbl
WHERE FixHours <> 0
AND AddHours <> 0

UNION

SELECT 0, AddHours, CalculatedValue
FROM tbl
WHERE FixHours <> 0
AND AddHours <> 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

How to split a single row into multiple rows in SQL

From Dev

How to split a row in multiple rows SQL Server?

From Dev

Split table row into two rows

From Dev

How to split 4 columns, one row into 2 columns, two rows?

From Dev

How to split a row into multiple rows between two given dates?

From Dev

How to split Dataframe row into two rows for a given condition -python

From Dev

Can a break/split a Row in sql into two different rows and display them as two rows

From Dev

MS Access SQL: Data from Two Columns on One Row Becomes Data in One Column on Two Rows

From Dev

How to subtract two consecutive rows in MS SQL Server?

From Dev

R - Split data frame row into two rows

From Dev

R split each row of a dataframe into two rows

From Dev

R split each row of a dataframe into two rows

From Dev

SQL : splitting a row in two rows

From Dev

How do I create two rows from one row SQL

From Dev

How to marge two rows and make single row in sql

From Dev

SQL Server - Split a row into multiple rows

From Dev

SQL - one row to split into two columns snake

From Dev

How to split row into many rows in postgresql

From Dev

How to split a row into 3 shorter rows in R

From Dev

How to split a time frame in one row to different quarters in different rows in T-SQL

From Dev

How to split a time frame in one row to different quarters in different rows in T-SQL

From Dev

How to split two cells into different numbers of rows?

From Dev

Creating multiple rows in an MS SQL table per row in another table

From Dev

How to split a row into two strings and copy the second string in a separate column in SQL?

From Dev

sql split one row to multiple rows based on number of columns available

From Dev

SQL: Split a row into multiple rows based on certain rules

From Dev

How to select two rows into a single row output

From Dev

How to Merge Two Specific Rows into One Row

From Dev

How to combine two rows in a spreadsheet into a single row?

Related Related

  1. 1

    How to split a single row into multiple rows in SQL

  2. 2

    How to split a row in multiple rows SQL Server?

  3. 3

    Split table row into two rows

  4. 4

    How to split 4 columns, one row into 2 columns, two rows?

  5. 5

    How to split a row into multiple rows between two given dates?

  6. 6

    How to split Dataframe row into two rows for a given condition -python

  7. 7

    Can a break/split a Row in sql into two different rows and display them as two rows

  8. 8

    MS Access SQL: Data from Two Columns on One Row Becomes Data in One Column on Two Rows

  9. 9

    How to subtract two consecutive rows in MS SQL Server?

  10. 10

    R - Split data frame row into two rows

  11. 11

    R split each row of a dataframe into two rows

  12. 12

    R split each row of a dataframe into two rows

  13. 13

    SQL : splitting a row in two rows

  14. 14

    How do I create two rows from one row SQL

  15. 15

    How to marge two rows and make single row in sql

  16. 16

    SQL Server - Split a row into multiple rows

  17. 17

    SQL - one row to split into two columns snake

  18. 18

    How to split row into many rows in postgresql

  19. 19

    How to split a row into 3 shorter rows in R

  20. 20

    How to split a time frame in one row to different quarters in different rows in T-SQL

  21. 21

    How to split a time frame in one row to different quarters in different rows in T-SQL

  22. 22

    How to split two cells into different numbers of rows?

  23. 23

    Creating multiple rows in an MS SQL table per row in another table

  24. 24

    How to split a row into two strings and copy the second string in a separate column in SQL?

  25. 25

    sql split one row to multiple rows based on number of columns available

  26. 26

    SQL: Split a row into multiple rows based on certain rules

  27. 27

    How to select two rows into a single row output

  28. 28

    How to Merge Two Specific Rows into One Row

  29. 29

    How to combine two rows in a spreadsheet into a single row?

HotTag

Archive