hai,
i have a table Queue_Number having columns ID , Queue_Type , Queue_Status , Reference_ID , QID , QNo , QID_No
i have written trigger for insertion in this QID , QNo , QID_No will be inserted automatically by the trigger which is shown below , i want to insert the remaining columns
Queue_Type , Reference_ID externally.
i am inserting Queue_Type , Reference_ID externally for that i am getting result as the two columns Queue_Type , Reference_ID are inserting in one row and the remaining
QID , QNo , QID_No inserting in another row.
CREATE TRIGGER QNO_GENERATION
ON Queue_Number
FOR INSERT
AS
BEGIN
DECLARE @QID_No NVarchar(25) = NULL
DECLARE @QId NVarchar(6) = NULL
DECLARE @QNo Int = 0
DECLARE @Month Int = 0
DECLARE @Queue_Type INT
DECLARE @Reference_ID INT
SELECT @QId=I.QID FROM INSERTED I
SELECT @QNo=I.QNo FROM INSERTED I
SELECT @QID_No=I.QID_No FROM INSERTED I
SELECT @Reference_ID=I.Reference_ID FROM INSERTED I
SET @Month = (SELECT DATEPART(MONTH,GETDATE()))
IF @Month > 3
BEGIN
SET @QId = (SELECT (CONVERT(NVARCHAR(4),DATEPART(Year,GETDATE())) + CONVERT(NVarchar(2),RIGHT((DATEPART(Year,DATEADD(Year,1,GETDATE()))),2))))
END
SET @QNo = (SELECT QNo FROM Queue_Number WHERE QID_No = @QId)
SET @QNo = @QNo + 1
SET @QID_No = @QId + (SELECT (CONVERT(NVarchar(10),@QNo)))
INSERT INTO Queue_Number (QID,QNo,QID_No,Queue_Type,Reference_ID) VALUES (@QId,@QNo,@QID_No,@Queue_Type,@Reference_ID)
SELECT @Reference_ID AS QueueNo
END