October 5, 2014 at 12:22 pm
Hello,
I Want to have an output from a stored proc.
The output must be displayed in a msgbox in vb.net.
If I work with this code (without the output) for the stored proc, it works well:
ALTER PROCEDURE [dbo].[spTelling]
@scannummer Nvarchar(13)
AS
BEGIN
SET NOCOUNT ON;
declare @productid int, @premium int,@prem int
select @premium = productid From Product Where scannummer = @scannummer
if count(@premium) = 1
begin
select @prem = productid From TELLING Where ProductId = @premium
if count(@prem) = 1
Update TELLING set Tal = Tal + 1 where ProductId = @prem
else
INSERT INTO Telling (ProductID, Tal, Date) VALUES (@premium,1,getdate())
end
END
If I put an output to the sp then it doesn't work:
ALTER PROCEDURE [dbo].[spTelling]
@scannummer Nvarchar(13)
AS
BEGIN
SET NOCOUNT ON;
declare @productid int, @premium int,@prem int
select @premium = productid From Product Where scannummer = @scannummer
if count(@premium) = 1
begin
select @prem = productid From TELLING Where ProductId = @premium
if count(@prem) = 1
Update TELLING set Tal = Tal + 1 where ProductId = @prem
else
INSERT INTO Telling (ProductID, Tal, Date) VALUES (@premium,1,getdate())
end
else
Declare @outscan nvarchar(13)
EXEC
@outscan= @scannummer OUTPUT
END
Can someone help me ?
Txs
October 5, 2014 at 2:03 pm
Quick thought, the output parameter must be declared with the output keyword
😎
ALTER PROCEDURE [dbo].[spTelling]
(
@scannummer Nvarchar(13)-- input only
@myOutputParam INT OUTPUT -- output parameter
)
AS
BEGIN
Then the keyword is used when executing the procedure
EXEC dbo.spTelling @myScanNum, @theOutput OUTPUT
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply