Can anyone please help with the following case concerning T-SQL:
If you have one stored procedure called SP_A which calls inside it's stored procedure called SP_B and you have the following instruction as the first line in SP_A: SET NOCOUNT ON. I know the NOCOUNT variable has a batch scope so it's worth to mention that there are no GO commands anywhere in the body of either stored procedures.
Will the NOCOUNT have effect in the child stored procedure (SP_B)?
Example SP_A code:
CREATE PROCEDURE dbo.SP_A
AS
BEGIN
SET NOCOUNT ON
EXEC dbo.SP_B
END
Example SP_B code:
CREATE PROCEDURE dbo.SP_B
AS
BEGIN
SELECT * FROM dbo.SOME_TABLE
END
Will the select from the SP_B procedure print number of affected rows?
SP_Look at this - GuidoGx row(s) affectedyou can see is what SSMS reports back when SQL Server tells it how many rows were affected. IfSP_Aturns it off andSP_Bdoes not turn it back on, then when you executeSP_A, you won't get back any counts of rows -- it's really as simple as that. (GOor not is not relevant because you can't use this anyway -- T-SQL statements cannot begin new batches themselves, so everything inside one stored procedure call, including any calls to other stored procedures, happen in the same batch.) - Jeroen MostertSP_Balways being called fromSP_A. It makes no sense to omitSET NOCOUNT ONas a sort of optimization. - Jeroen MostertGOcommands in the proc body, that's not worth mentioning since it impossible to includeGOcommands in a in a stored procedure. TheGObatch separator is not a T-SQL command and is only recognized by SQL Server tools and some SMO APIs. - Dan Guzman