【发布时间】:2013-03-17 23:30:21
【问题描述】:
我正在尝试存储 NOCOUNT 状态,以便在我的程序结束时将其恢复为原始状态,但它所做的只是给我一个 Incorrect syntax near 'NOCOUNT'. 错误。
我做错了什么?
IF @@OPTIONS & 512 <> 0 /* check original state of NOCOUNT */
PRINT N'This user has SET NOCOUNT turned ON.';
ELSE
PRINT N'This user has SET NOCOUNT turned OFF.';
DECLARE @NCStat bit
SET @NCStat = ( @@OPTIONS & 512 ) /* sets @NCStat to original state of NOCOUNT */
SET NOCOUNT ON ;
IF @@OPTIONS & 512 <> 0 /* verify state of NOCOUNT */
PRINT N'This user has SET NOCOUNT turned ON.';
ELSE
PRINT N'This user has SET NOCOUNT turned OFF.';
PRINT N'NCStat = ' + cast(@NCStat as nvarchar) ; /* verify value of @NCStat */
/* line 23 */ SET NOCOUNT @NCStat ; /* return NOCOUNT to original state */
IF @@OPTIONS & 512 <> 0 /* verify state of NOCOUNT */
PRINT N'This user has SET NOCOUNT turned ON.';
ELSE
PRINT N'This user has SET NOCOUNT turned OFF.';
GO
如果第 23 行被注释掉,所有其他行都可以正常工作,但第 23 行给出了上述错误。
【问题讨论】:
标签: sql sql-server tsql sql-server-2012-express