J
Jack
Hi,
I got a union query which works fine. However it needs to change based on
the current month. Thus it needs to be dynamic in nature.
I am not aware how to do this. However the concept would be somewhat like
the following.
I appreciate any help for resolution of this issue. Thanks.
If Month(Date()) = 7 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, Null, Null, Null, Null, Null, Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 8 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, Null, Null, Null, Null, Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 9 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, Null, Null, Null, Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 10 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, month09, Null, Null,
Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 11 THen
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, month09, month10, Null,
Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 12 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, month09, month10,
Month11, Null
from Row4Sample1_Variance_transformed;
I got a union query which works fine. However it needs to change based on
the current month. Thus it needs to be dynamic in nature.
I am not aware how to do this. However the concept would be somewhat like
the following.
I appreciate any help for resolution of this issue. Thanks.
If Month(Date()) = 7 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, Null, Null, Null, Null, Null, Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 8 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, Null, Null, Null, Null, Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 9 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, Null, Null, Null, Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 10 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, month09, Null, Null,
Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 11 THen
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, month09, month10, Null,
Null
from Row4Sample1_Variance_transformed;
If Month(Date()) = 12 Then
select * from Row1Sample_LastYearSales1_transformed
union all
select * from Row2Sample_LastYearBudget1_transformed
UNION ALL select * from Row3Sample1_ThisYearsForecast_tranformed;
union all select slsman, custnum, name, grandtotal, month01, month02,
month03, month04, month05, month06, month07, month08, month09, month10,
Month11, Null
from Row4Sample1_Variance_transformed;