Sql-Server-2012
為什麼 SSMS 的行數經常出錯?
我試圖讓一些程式碼執行經過時間測試的“執行,Google搜尋紅色文本,執行 SO 所說,重複”方法,我注意到錯誤處理程序的行數通常是錯誤的。
例如,在這個儲存過程中它是正確的:
create procedure why_it_be_like_dis as select * from INFORMATION_SCHEMA.tables where column_name like '%bananna%'
但在現實世界的例子中,它將關閉:
**問題:**為什麼行號總是不匹配?
錯誤資訊:
消息 207,級別 16,狀態 1,過程刪除 from_and_load,第 21 行
$$ Batch Start Line 7 $$ 列名“SRGY_STM_LKP_ID”無效。 完整的sp:
USE [SRGRY_DMART_ETL] GO /****** Object: StoredProcedure [dbo].[delete from_and_load] Script Date: 7/22/2020 8:20:28 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[delete from_and_load] AS BEGIN DECLARE @btch_start DATETIME ,@btch_end DATETIME SELECT @btch_start = getdate() EXEC [dbo].[snapshot_constraints] EXEC dbo.drop_all_constraints delete from [dbo].[CASE_2_PAT_CASE_BRG]; delete from [dbo].[CASE_2_PVDR_BRG]; delete from [dbo].[CASE_2_DGNS_BRG]; delete from [dbo].[CASE_2_PCD_BRG]; delete from [dbo].[CASE_2_DLAY_RSN_BRG]; DELETE FROM [dbo].[CASE_FCT] where SRGY_STM_LKP_ID in (111,333); DELETE FROM [dbo].[PAT_CASE_FCT] where SRGY_STM_LKP_ID in (111,333); DELETE FROM [dbo].[PVDR_RL_DIM] where STM_LKP_ID in (111,333); DELETE FROM [dbo].[ADM_TP_DIM] where SRGY_STM_LKP_ID in (111,333) DELETE FROM [dbo].[ANES_TP_DIM] where SRGY_STM_LKP_ID in (111,333) DELETE FROM [dbo].[CNCL_RSN_DIM] where SRGY_STM_LKP_ID in (111,333); DELETE FROM [dbo].[DLAY_IND_DIM] where SRGY_STM_LKP_ID in (111,333); delete from [dbo].[LOC_IDN_ARR] where STM_LKP_ID in (111,333); delete from [dbo].[PTNT_IDN_ARR] where STM_LKP_ID in (111,333); -- V6 - delete from / DELETE { From Sooraj } delete from DBO.PTNT_INSR_ARR where STM_LKP_ID in (111,333) DELETE FROM [dbo].[PVDR_DIM] where STM_LKP_ID in (111,333) -- YOU COULD TRY THE DEFAULT INSERT at a streatch DELETE FROM [dbo].[PTNT_DIM] where STM_LKP_ID in (111,333) DELETE FROM [dbo].[LOC_DIM] where STM_LKP_ID in (111,333) -- ################## Abraham's Improvised Idea of SCM OR LOC ID ################## END -- -- v5 SP list from Towsif PRINT '[dbo].[PROC_PATIENT_INSERT]' EXEC [dbo].[PROC_PATIENT_INSERT] PRINT '[dbo].[PROC_PTNTINSR_ARR_INSERT]' EXEC [dbo].[PROC_PTNTINSR_ARR_INSERT] PRINT '[dbo].[PROC_PVDR_DIM_INSERT]' EXEC [dbo].[PROC_PVDR_DIM_INSERT] PRINT 'dbo.PROC_LOC_FCY_HIER_INSERT' EXEC dbo.PROC_LOC_FCY_HIER_INSERT PRINT '[dbo].[PROC_LOC_IDN_ARR_INSERT]' EXEC [dbo].[PROC_LOC_IDN_ARR_INSERT]; PRINT '[dbo].[PROC_DLAY_IND_DIM_INSERT]' EXEC [dbo].[PROC_DLAY_IND_DIM_INSERT]; PRINT '[dbo].[PROC_CNCL_RSN_DIM_INSERT]' EXEC [dbo].[PROC_CNCL_RSN_DIM_INSERT]; PRINT '[dbo].[PROC_ANES_TP_DIM_INSERT]' EXEC [dbo].[PROC_ANES_TP_DIM_INSERT]; PRINT '[dbo].[PROC_ADM_TP_DIM_INSERT]' EXEC [dbo].[PROC_ADM_TP_DIM_INSERT]; PRINT '[dbo].[PROC_PVDR_RL_DIM_INSERT]' EXEC [dbo].[PROC_PVDR_RL_DIM_INSERT]; PRINT '[dbo].[PROC_PAT_CASE_FCT_INSERT]' EXEC [dbo].[PROC_PAT_CASE_FCT_INSERT]; PRINT '[dbo].[PROC_CASE_FCT_INSERT]' EXEC [dbo].[PROC_CASE_FCT_INSERT]; PRINT '[dbo].[PROC_PTNT_IDN_ARR_INSERT]' EXEC [dbo].[PROC_PTNT_IDN_ARR_INSERT];-- This should execute after PTNT_DIM has been loaded.” PRINT '[dbo].[PROC_PTNT_DIM_EMPI_UPDATE]' EXEC [dbo].[PROC_PTNT_DIM_EMPI_UPDATE]; PRINT '[dbo].[PROC_CASE_2_DLAY_RSN_BRG_INSERT]' EXEC [dbo].[PROC_CASE_2_DLAY_RSN_BRG_INSERT]; PRINT '[dbo].[PROC_CASE_PCD_BRG_INSERT]' EXEC [dbo].[PROC_CASE_PCD_BRG_INSERT]; PRINT '[dbo].[PROC_CASE_DGNS_BRG_INSERT]' EXEC [dbo].[PROC_CASE_DGNS_BRG_INSERT]; PRINT '[dbo].[PROC_CASE_PVDR_BRG_INSERT]' EXEC [dbo].[PROC_CASE_PVDR_BRG_INSERT]; PRINT '[dbo].[PROC_CASE_2_PAT_CASE_BRG_INSERT]' EXEC [dbo].[PROC_CASE_2_PAT_CASE_BRG_INSERT]; PRINT 'dbo.PROC_CASE_VST_IDN_ARR_INSERT' EXEC dbo.PROC_CASE_VST_IDN_ARR_INSERT; PRINT 'dbo.PROC_SVC_DIM_INSERT' EXEC dbo.PROC_SVC_DIM_INSERT; PRINT 'dbo.PROC_GRP_DIM_INSERT' EXEC dbo.PROC_GRP_DIM_INSERT; PRINT '[dbo].[PROC_PVDR_2_SVC_BRG_INSERT]' EXEC [dbo].[PROC_PVDR_2_SVC_BRG_INSERT]; PRINT '[dbo].[PROC_PVDR_2_GRP_BRG_INSERT]' EXEC [dbo].[PROC_PVDR_2_GRP_BRG_INSERT] PRINT 'dbo.[PROC_BLC_DIM_INSERT]' EXEC dbo.[PROC_BLC_DIM_INSERT] --print '[dbo].[PROC_BLC_SHD_BRG_INSERT]' --exec [dbo].[PROC_BLC_SHD_BRG_INSERT] PRINT '[dbo].[PROC_BLC_2_OWN_BRG_INSERT]' EXEC [dbo].[PROC_BLC_2_OWN_BRG_INSERT] --PRINT 'dbo.PROC_SCM_HH_PAT_CASE_INS' --EXEC dbo.PROC_SCM_HH_PAT_CASE_INS PRINT 'dbo.PROC_SCM_SIUH_PAT_CASE_INS' EXEC dbo.PROC_SCM_SIUH_PAT_CASE_INS EXEC dbo.add_all_constraints ---exec dbo.proc_record_counts --exec dbo.proc_column_counts SELECT @btch_end = getdate() INSERT INTO dbo.BTCH_LOG ( BTCH_STRT_TS ,BTCH_END_TS ) VALUES ( @btch_start ,@btch_end ) --exec dbo.proc_etl_stat_log_ins END
消息 207,級別 16,狀態 1,過程刪除 from_and_load,第 21 行
$$ Batch Start Line 7 $$列名“SRGY_STM_LKP_ID”無效。
請注意錯誤消息顯示“批處理開始行…”。編譯錯誤的行號是相對於批處理的開始,而不是整個腳本。如果添加錯誤行和批處理開始行號 (21 + 7),則 28 的結果是腳本中的行號。