All queries combined using a UNION, INTERSECT or EXCEPT

Simple Union query resulting in the error (All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.). I double checked the columns and everything looks good. What other reason(s) would cause this resulting error?

select OpportunityOwner, RecordType, ForecastCategory, CaseSafeOppID, date, [Fiscal Qtr], CloseDate,
MasterLicenseAmt, TrueMCVEst, MasterLicenseAmt + TrueMCVEst "Total $"
from ds_adhoc_sops.Pipe.DailyLicMCV

union

select OpportunityOwner, RecordType, ForecastCategory, CaseSafeOppID, date, [Fiscal Qtr], CloseDate
MasterLicenseAmt, TrueMCVEst, MasterLicenseAmt + TrueMCVEst "Total $"
from ds_adhoc_sops.Pipe.QTRLicMcvWL
;

Thank you

>Solution :

You are missing a comma in the second part of the union statement, therefore the column size is different.

Try this:

select OpportunityOwner, RecordType, ForecastCategory, CaseSafeOppID, date, [Fiscal Qtr], CloseDate,
    MasterLicenseAmt, TrueMCVEst, MasterLicenseAmt + TrueMCVEst "Total $"
    from ds_adhoc_sops.Pipe.DailyLicMCV

union

select OpportunityOwner, RecordType, ForecastCategory, CaseSafeOppID, date, [Fiscal Qtr], CloseDate,
MasterLicenseAmt, TrueMCVEst, MasterLicenseAmt + TrueMCVEst "Total $"
from ds_adhoc_sops.Pipe.QTRLicMcvWL
;

Leave a Reply