'SQL increment value with values variable
I have this SQL Server procedure:
ALTER PROCEDURE [dbo].[AddBagTab]
@LotNumber nvarchar(15),
@CounterPart nvarchar(7)
AS
BEGIN
DECLARE @ile INT
SELECT @ile = COUNT(*)
FROM PrinterArchive
WHERE LotNumber = @LotNumber
AND CounterPart = @CounterPart
IF @ile = 0
INSERT INTO PrinterArchive(LotNumber, CounterPart, DataInsert)
VALUES (@LotNumber, @CounterPart, GETDATE())
ELSE
PRINT 'Taki worek już istnieje'
END
I need it to insert into a table with three columns.
It should insert records according to:
LotNumber: CounterPart
272181121032: 00001
272181121032: 00002
272181121032: 00003
etc.
The CounterPart value is set in the variable field as 00001 and depends on the value of the field in another variable, i.e. if I choose a batch and enter 10 in the application column, it should increase the values from 00001 to 00010 for me and at the next calculation it should increase from 00011.
I don't know how I can achieve it in the procedure, what to modify?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
