Skip to content
Advertisement

To UNION or Not to UNION

I am currently running into an issue with my UNION clause. I am trying to figure out how many orders I am import via each day. The problem is, I have two tables that these orders are stored in OLDORDERHEADER and ORDERHEADER. After an order is completed, it moves from the ORDERHEADER table into the OLD. Both have the same exact columns, so I figured I would use a UNION clause and be fine. Well once I run my query, it prints two rows, identical dates and different qtys’. Which is to be expected, I just want to combine them into one row and a sum of the qty’s for each hour. Here is what I am working with:

Advertisement

Answer

You might also consider PIVOT for a more concise syntax.

I find the use of UNION dubious and am assuming that you actually need UNION ALL too.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement