declare @IDATE as DATE = '20240312'

use dy2023 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2022 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2021 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2020 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2019 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2018 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2017 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2016 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

use dy2015 
insert into GOVWIN_BATCH (PROPERTYKEY, I_U, BILL_NO, BILL_YEAR, TRANSMIT)
select b.propertykey, 'U', b.bill_no, b.bill_year, 0 
from bill b 
inner join DY2023.dbo.INTEREST_RP x on x.BILL_NO=b.BILL_NO and x.BILL_YEAR=b.BILL_YEAR and x.BILL_TYPE=b.BILL_TYPE where convert(date,x.I_APPLYDATE)=@IDATE

