我有以下代碼。當執行它打印,因爲它不是在聚合包含 抑制SQL Server 2008中的錯誤消息
消息8120,級別16,狀態1,過程測試,行17
列「@ t.Country」在選擇列表中無效函數或GROUP BY子句。錯誤'
但我只想打印'ERROR'
。有沒有辦法抑制錯誤信息?
感謝 SatyaprakashĴ
CREATE PROCEDURE Test
AS
DECLARE @t TABLE
(ID INT IDENTITY(1,1)
,Country NVARCHAR(50)
,Year INT
,PopulationInMillions INT
)
INSERT @t (Country, Year, PopulationInMillions)
VALUES ('US', 2000, 20),
('US', 2001, 22)
SELECT Country, MAX(PopulationInMillions)
FROM @t
GO
BEGIN TRY
EXEC Test
END TRY
BEGIN CATCH
PRINT 'ERROR'
END CATCH
錯誤發自'CREATE PROC'而不是'EXEC' –