我有以下代码。执行时打印
消息 8120,级别 16,状态 1,过程测试,第 17
行列“@t.Country”在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。错误'
但我只想'ERROR'
被打印出来。有没有办法抑制错误消息?
谢谢 Satyaprakash J
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