What is better to return a single value in TSQL stored procedure: a RETURN or an OUTPUT?
Date : March 29 2020, 07:55 AM
should help you out Use an output parameter. It is less resource intensive to deal with a scalar parameter than a dataset via SELECT (or an OUTPUT clause etc) in the client
|
Return Output Param of a Stored Procedure inside another Stored Procedure
Date : March 29 2020, 07:55 AM
wish helps you If this isn't really an output parameter issue at all, but rather a result set, then taking a guess that SpWithOutputID does something like this (returns a SELECT with a single row and single column): CREATE PROCEDURE dbo.SpWithOutputID
AS
BEGIN
SET NOCOUNT ON;
SELECT ID = 4;
END
GO
CREATE PROCEDURE dbo.Test1
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ID INT;
CREATE TABLE #x(ID INT);
INSERT #x EXEC dbo.SpWithOutputID;
SELECT TOP (1) @ID = ID FROM #x;
DROP TABLE #x;
END
GO
CREATE PROCEDURE dbo.SpWithOutputID
@ID INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT @ID = 4;
END
GO
CREATE PROCEDURE dbo.Test1
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ID INT;
EXEC dbo.SpWithOutputID @ID = @ID OUTPUT;
SELECT @ID;
END
GO
|
Read INSERT output from stored procedure
Date : March 29 2020, 07:55 AM
this one helps. I have a following stored procedure , Try this: -- count use a temp table as well
-- syntax: CREATE TABLE #t(CategoryId int,[Timestamp] datetime)
DECLARE @t table(CategoryId int,[Timestamp] datetime)
INSERT @t(CategoryId, [TimeStamp])
EXEC [dbo].[InsertCategory] @Name= @Name
SELECT CategoryId, [TimeStamp]
FROM @t
|
SQL return the output of SELECT and not the output of another stored procedure
Tag : sql , By : user134570
Date : March 29 2020, 07:55 AM
should help you out How do I return the result of the SELECT as the output of the stored procedure? Sorry I'm new to stored procedures! , Put the results into a table variable instead: create procedure dbo.usp_Child
as
begin
select N'Hello world!' as [message];
end;
go
create procedure dbo.usp_Main
as
begin;
declare @results table ([message] nvarchar(max));
insert into @results
execute dbo.usp_Child;
select N'success';
end;
go
execute dbo.usp_Main;
|
C# to read OUTPUT value from stored procedure
Tag : chash , By : user181945
Date : March 29 2020, 07:55 AM
wish helps you You're missing a output parameter. The TSQL would look something like: command = new SqlCommand($@"EXECUTE dbo.Votes @VotedMember = @p_VotedMember,
@VotedBy = @p_VotedBy,
@p_votecount = @votecount output",
StaticObjects._connection);
var pVotecount = command.Parameters.Add("@p_votecount", SqlDbType.Int);
pVotecount.Direction = ParameterDirection.Output;
command = new SqlCommand($@"EXECUTE @p_votecount = dbo.Votes @VotedMember = @p_VotedMember,
@VotedBy = @p_VotedBy",
StaticObjects._connection);
|