I have the following statement:
DECLARE @Nr_Karton int;
SELECT @Nr_Karton = ISNULL(MAX(Nr), 1000) FROM W_Karton;
SET @Nr_Karton = @Nr_Karton + 1;
INSERT INTO W_Karton (Container_ID, Nr, Beschrieb, CreationDate, Location)
VALUES ('1', @Nr_Karton, '', getDate(), 'Bösingen');
But I get the error:
[SQL] SELECT @Nr_Karton = ISNULL(MAX(Nr), 1000) FROM W_Karton
[Err] 42000 - [SQL Server]Must declare the scalar variable "@Nr_Karton".
How to get rid of the error?
IDENTITY
column instead of generating ID values yourself. – PondlifeAUTO_INCREMENT
in MySQL. – BridgeISNULL(MAX(Nr), 1000)
in place. But the error says Variable not defined which is weird. – Kaf