Ok, I've got a TSQL query that I'm looking to clean up. I've got it working as is, but it just seems like a bass-ackwards way to achieve what I'm looking for and since this is being referenced by another query that is just running too slow, I'm hoping to speed it up.
My goal is, I have two databases: YearCurrent, and YearFuture. They contain a list of records and in MOST cases are the same. Whenever they're the same, I only care about the current record. If they're different, I need both. The records need to be aggregated into a single list though with in indication as to whether or not the record came from the current year or the future.
Right now I have the following:
SELECT
*,
'C' AS C_OR_F
FROM YearCurrent.dbo.ExtractSummary
UNION
SELECT
*,
'F' AS C_OR_F
FROM
(
SELECT *
FROM YearFuture.dbo.ExtractSummary
EXCEPT
SELECT *
FROM YearCurrent.dbo.ExtractSummary
) AS FUTURES_ONLY
That's just requerying the same exact data too many times though.
Anybody have any idea on how to just merge the datasets once and insert the C_OR_F value depending on which database the record came from?
Alternatively I'd love if I could somehow specify a list of fields for comparison on the EXCEPT and UNION operators.
Thanks.
My goal is, I have two databases: YearCurrent, and YearFuture. They contain a list of records and in MOST cases are the same. Whenever they're the same, I only care about the current record. If they're different, I need both. The records need to be aggregated into a single list though with in indication as to whether or not the record came from the current year or the future.
Right now I have the following:
SELECT
*,
'C' AS C_OR_F
FROM YearCurrent.dbo.ExtractSummary
UNION
SELECT
*,
'F' AS C_OR_F
FROM
(
SELECT *
FROM YearFuture.dbo.ExtractSummary
EXCEPT
SELECT *
FROM YearCurrent.dbo.ExtractSummary
) AS FUTURES_ONLY
That's just requerying the same exact data too many times though.
Anybody have any idea on how to just merge the datasets once and insert the C_OR_F value depending on which database the record came from?
Alternatively I'd love if I could somehow specify a list of fields for comparison on the EXCEPT and UNION operators.
Thanks.