I've got a sp that goes well.except for the tinyint value, that doesn't update in the table.ALTER PROCEDURE [dbo].[spTelling]( @ScanNummer NVARCHAR(13), @Basis tinyint, @CurrentTal INT OUT)AS-- Prevent unwanted resulsets back to clientSET NOCOUNT ON;-- Prepare output valueDECLARE @Return TABLE ( Value INT NOT NULL );MERGE dbo.Telling AS tgtUSING ( SELECT TOP(1) ProductID, 1 AS Tal, GETDATE() AS [Date],@Basis as Basis FROM dbo.Product WHERE ScanNummer = @ScanNummer ) AS src ON src.ProductID = tgt.ProductIDWHEN MATCHED THEN UPDATE SET tgt.Tal += src.Tal WHEN NOT MATCHED BY TARGET THEN INSERT ( ProductID, Tal, [Date], Basis ) values ( src.ProductID, src.Tal, src.[Date], src.Basis )OUTPUT inserted.TalINTO @Return ( Value );SELECT @CurrentTal = ISNULL(Value, CAST(@Scannummer AS INT))FROM @Return;
The insert statement works. ButI want also to update Basis (tinyint) in the table Telling.WHEN MATCHED THEN UPDATE SET tgt.Tal += src.Tal
Where must I write set basis = @Basisif you do not try, it will not work