Hallo,
folgendes Beispiel:
-- called proc
create or alter proc foobar
as
-- modify nocount option
IF @@OPTIONS & 512 > 0 RAISERROR ('foobar #1: NOCOUNT turned on.', 1, 1) ELSE RAISERROR ('foobar #1: NOCOUNT turned off.', 1, 1);
SET NOCOUNT ON;
IF @@OPTIONS & 512 > 0 RAISERROR ('foobar #2: NOCOUNT turned on.', 1, 1) ELSE RAISERROR ('foobar #2: NOCOUNT turned off.', 1, 1);
GO
-----------------------------------
-- main script
IF @@OPTIONS & 512 > 0 RAISERROR ('main #1: NOCOUNT turned on.', 1, 1) ELSE RAISERROR ('main #1: NOCOUNT turned off.', 1, 1);
exec foobar;
IF @@OPTIONS & 512 > 0 RAISERROR ('main #2: NOCOUNT turned on.', 1, 1) ELSE RAISERROR ('main #2: NOCOUNT turned off.', 1, 1);
GO
In der aufgerufenen SP wird die Option NOCOUNT umgesetzt. Im aufrufenden Skript ist die Option nach Abschluss der SP jedoch nicht gesetzt. Dieses Verhalten ist total plausibel und gut so, allerdings finde ich keinerlei Dokumentation darüber. Kann mir jemand
auf die Sprünge helfen?
Ich bereite aktuell eine SQL Schulung für Azubis vor und möchte das etwas besser erklären können.
main #1: NOCOUNT turned off.
Msg 50000, Level 1, State 1
foobar #1: NOCOUNT turned off.
Msg 50000, Level 1, State 1
foobar #2: NOCOUNT turned on.
Msg 50000, Level 1, State 1
main #2: NOCOUNT turned off.
Msg 50000, Level 1, State 1
Vielen Dank!