CREATE PROCEDURE `spAutoFeeSetupMonthly` ( IN `P_TeacherId` INTEGER , IN `P_BatchId` INTEGER ) BEGIN INSERT INTO `tfeesetup` ( `TeacherId` , `BatchId` , `StudentId` , `FeeAmount` , `IsRecurringMonthly` , `DateOfFeeCollection` , `CreatedDateTime` , `CreatedUserId` , `DefaultFeeAmount` , `SetupDate` , `IsSendSMSFeeDue` , `IsSendNotificationFeeDue` ) SELECT `F` . `TeacherId` , `F` . `BatchId` , `F` . `StudentId` , `F` . `FeeAmount` , ? , ( `F` . `DateOfFeeCollection` + INTERVAL ? SQL_TSI_MONTH ) AS `DateOfFeeCollection` , ( `F` . `CreatedDateTime` + INTERVAL ? SQL_TSI_MONTH ) AS `CreatedDateTime` , `F` . `CreatedUserId` AS `CreatedUserId` , `F` . `DefaultFeeAmount` AS `DefaultFeeAmount` , ( `F` . `SetupDate` + INTERVAL ? SQL_TSI_MONTH ) AS `SetupDate` , `F` . `IsSendSMSFeeDue` , `F` . `IsSendNotificationFeeDue` FROM `tfeesetup` `F` WHERE `F` . `TeacherId` = `P_TeacherId` AND `F` . `BatchId` = `P_BatchId` AND SQL_TSI_MONTH ( `F` . `SetupDate` ) = SQL_TSI_MONTH ( NOW ( ) - INTERVAL ? SQL_TSI_MONTH ) AND YEAR ( `F` . `SetupDate` ) = YEAR ( NOW ( ) - INTERVAL ? SQL_TSI_MONTH ) ; END 