Hi Frndz,
Functionality: Check Month Exist
To achieve this task,
Make one function that check month and fundid record exist or not.
Check VerifyExistData function
After then make one SP and pass paramerter Fundid, TransactionType
Now check Exist month for particular ID or not
SET @Flag = dbo.VerifyExistData(@FundID)
Check below function and SP
Full Logic :
Function for check Month Record Exist or not
CREATE FUNCTION [dbo].[VerifyExistData]
(
@FundID INT
)
RETURNS BIT
AS
BEGIN
DECLARE @rtnValue as BIT = 1
IF EXISTS
(
Select
[Date]
from
[Transaction]
where [FundID] = @FundID
AND DatePart(month, [Date]) = DATEPART(month,getdate())
AND DatePart(year, [Date]) = DATEPART(YEAR,getdate())
)
BEGIN
SET @rtnValue = 0;
END
RETURN @rtnValue ;
END
Stored Procedure for Insert Record into Transaction Table
CREATE PROCEDURE [dbo].[InsertTransaction]
@FundID AS INT,
@TransactionType AS Varchar(255)
AS
Declare @Flag AS BIT
SET @Flag = dbo.VerifyExistData(@FundID)
IF (@Flag = 1)
BEGIN
INSERT INTO [Transaction](FundID,TransactionType,[Date]) values (@FundID,@TransactionType,GETDATE())
END
Hope this helpful!
Thanks