RE: SQL statement to Modify Items and comments
I've wrote this, but I'm getting the following error
Msg 515, Level 16, State 2, Line 35
Cannot insert the value NULL into column 'Line No_', table 'LH_RESTORE_20171211.dbo.TIOGA$Comment Line'; column does not allow nulls. INSERT fails.
DECLARE @ItemNo VARCHAR(50)
DECLARE @Comment VARCHAR(250)
DECLARE @LineNo INT;
-- Set the variables
SET @Comment = 'Unit of Measure parts must be reviewed'
-- Select the Items which need amending
DECLARE db_Cursor CURSOR FOR
SELECT [No_]
from dbo.[TIOGA$Production BOM Line] L
where [Unit of Measure Code] = 'EACH'
and [Quantity per] < 1
AND [Quantity per] != 0
AND [Version Code] = ''
OPEN db_Cursor
FETCH NEXT FROM db_Cursor INTO @ItemNo
WHILE @@FETCH_STATUS = 0
BEGIN
-- Get the last Line No.
select @LineNo = max([Line No_]) from dbo.[TIOGA$Comment Line] C
where [No_] = @ItemNo
and [Table Name] = 3
SET @LineNo = @LineNo + 10000;
-- Set Blocked on the Item
update dbo.[TIOGA$Item]
set [Blocked] = 1
where [No_] = @ItemNo
-- Insert the comment line
INSERT INTO dbo.[TIOGA$Comment Line] ([Table Name],[No_],[Line No_],[Date],
[Code],[Comment],[Comment Type],[Indentation],[Complete])
VALUES (3,@ItemNo,@LineNo,'20/12/2017','',@Comment,0,0,0)
FETCH NEXT FROM db_cursor INTO @ItemNo
END
CLOSE db_Cursor
DEALLOCATE db_cursor