For example:
CREATE PROCEDURE dbo.MyProc
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
...
DECLARE @Id INT;
-- I don't want the following line to throw and abort processing.
-- I just want @Id to remain NULL. I can add a nested TRY/CATCH, but is there
-- a better way?
SET @Id=(SELECT Id FROM MyTable WHERE ...);
...
END TRY
BEGIN CATCH
...
END CATCH;
END;
Update: Just to clarify, if multiple rows are returned, I want @Id to stay NULL.
I will do something like this to avoid multiple rows errors:
or this
This last piece will set the @Id to null when there were multiple rows.