这个函数从最后一个 GO (批分隔符)语句开始计数,所以如果您没有使用任何 GO 空格,并且它仍然显示错误的行号——那么向它添加7,就像在第7行的存储过程中一样,批分隔符是自动使用的。所以如果你用
选择 Cast (Error _ Number () + 7 as Int) as [ Error _ Number ]-您将得到所需的答案。
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE ErrorTesting
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT 1/0
END
GO
创建完成后,可以将其切换到 ALTER PROCEDURE,并在注释上方和第一个 GO语句上下添加一些空行,以查看效果。
USE [Northwind]
GO
/****** Object: StoredProcedure [automate].[workorders_exceptions_generate] Script Date: 03/03/2021 8:49:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
Here are some comments here
Which are white spaces
But the actual line after the "BEGIN" statement is 21
*/
CREATE PROCEDURE dbo.something
@ChildWOID varchar(30)
, @DontByPass bit = 0
, @BillingStatus varchar(30) = null OUTPUT
AS
BEGIN
LINENO 21
PRINT 'HELLO WORLD'
END