GM all. Hoping you are all safe these days.
Question on the best practice for plugging a value in a Union All query
I need to Union All the following two tables:
Table 1 Has an Account's Market Value for each day
TABLE 1 FIELDS
AccountNumber
Date
MarketValue
Table 2 has an Accounts Activity for Each Day
TABLE 2 FIELDS
AccountNumber
Date
Activity
(not every day has both a Market Value and Activity, so UNION ALL is needed)
I don't know the best way to handle the missing value in each table. I'd rather not plug 0's and then add them. Seems like there must be a better way.
The goal is to get all 4 fields on the same row
I can do this but...
**************
SELECT
AccountNumber,
Date,
MarketValue,
0 as Activity
FROM TABLE 1
Union All
AccountNumber,
Date,
0 as MarketValue,
Activity
FROM TABLE 2
**********
I could Group AccountNumber and Date, and then Sum MarketValue and Activity...
but can I avoid adding the zeros and then summing those fields?
Question on the best practice for plugging a value in a Union All query
I need to Union All the following two tables:
Table 1 Has an Account's Market Value for each day
TABLE 1 FIELDS
AccountNumber
Date
MarketValue
Table 2 has an Accounts Activity for Each Day
TABLE 2 FIELDS
AccountNumber
Date
Activity
(not every day has both a Market Value and Activity, so UNION ALL is needed)
I don't know the best way to handle the missing value in each table. I'd rather not plug 0's and then add them. Seems like there must be a better way.
The goal is to get all 4 fields on the same row
I can do this but...
**************
SELECT
AccountNumber,
Date,
MarketValue,
0 as Activity
FROM TABLE 1
Union All
AccountNumber,
Date,
0 as MarketValue,
Activity
FROM TABLE 2
**********
I could Group AccountNumber and Date, and then Sum MarketValue and Activity...
but can I avoid adding the zeros and then summing those fields?