StayAtHomeMom
Technical User
Hello all,
Can Union queries have WHERE clauses? I tried to insert one, and the "union" part doesn't work. The one query I use grabs data for the current year, and one query grabs data totals for the last year, and I merge, or union, them together. It works great until I tried adding a conditional where, and now I get one line for current year data, and one line with the last year data totals. Can anyone offer suggestions, or tell me if this is even possible?
MY UNION QUERY:
SELECT [Divn] , [RSM#], [RSMName], [TerrNo], [RepName], [DistName], [Jan], [Feb], [Mar], [Apr], [May], [Jun], [Jul], [Aug], [Sep], [Oct], [Nov], [Dec], [YTD Cost], [LY Cost] FROM [RPT115A-Cost by RSM-Terr-Dist] WHERE (([Divn])="ETUTL") UNION SELECT [Divn] , [RSM#], [RSMName], [TerrNo], [RepName], [DistName], [Jan], [Feb], [Mar], [Apr], [May], [Jun], [Jul], [Aug], [Sep], [Oct], [Nov], [Dec], [YTD Cost], [LY Cost] FROM [RPT115B-Cost by RSM-Terr-Dist] WHERE (([Divn])="ETUTL");
Again, it works great if I take out the WHERE clauses.
Thanks for your brilliant assistance!
Can Union queries have WHERE clauses? I tried to insert one, and the "union" part doesn't work. The one query I use grabs data for the current year, and one query grabs data totals for the last year, and I merge, or union, them together. It works great until I tried adding a conditional where, and now I get one line for current year data, and one line with the last year data totals. Can anyone offer suggestions, or tell me if this is even possible?
MY UNION QUERY:
SELECT [Divn] , [RSM#], [RSMName], [TerrNo], [RepName], [DistName], [Jan], [Feb], [Mar], [Apr], [May], [Jun], [Jul], [Aug], [Sep], [Oct], [Nov], [Dec], [YTD Cost], [LY Cost] FROM [RPT115A-Cost by RSM-Terr-Dist] WHERE (([Divn])="ETUTL") UNION SELECT [Divn] , [RSM#], [RSMName], [TerrNo], [RepName], [DistName], [Jan], [Feb], [Mar], [Apr], [May], [Jun], [Jul], [Aug], [Sep], [Oct], [Nov], [Dec], [YTD Cost], [LY Cost] FROM [RPT115B-Cost by RSM-Terr-Dist] WHERE (([Divn])="ETUTL");
Again, it works great if I take out the WHERE clauses.
Thanks for your brilliant assistance!