Raiserror doesn't output messages

Naomi Nosonovsky 8,861 Reputation points
2025-11-03T13:53:02.7566667+00:00

Hi everybody,

I have a strange problem. I have a long procedure which has 2 places that send notes for other procedure. This procedure outputs NULL by this line of code:

DECLARE @message VARCHAR(200) = ' Notes is ' + ISNULL(@notes, 'NULL')
		 RAISERROR (@message,  0, 1) WITH NOWAIT

It outputs Notes is NULL.

In the calling procedure I have the following:

SET @notes = 'NPI ' + ISNULL(@npi,'') + ' excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD ('
									+ CONVERT(VARCHAR(10), ISNULL(@inp_partition_id,0)) + 
									'LEN(@Snapshot) = ' + CAST(LEN(ISNULL(@Snapshot, 'NULL')) AS VARCHAR (10)) +
									') ' + ISNULL(ERROR_MESSAGE(),'');
                       RAISERROR (@notes, 0, 1) WITH NOWAIT
						EXECUTE dbo.usp_DevOps_Add_Exclusion_Mod
							@ExcludedId = @ProviderID
							, @ExtractType = @inp_extract_type
							, @notes = @notes;
					    
					FETCH NEXT FROM SplitProviderCursor
					INTO
						@myrowid
						, @Npi;
						SET @excludedProviders1 = @excludedProviders1+1
						RAISERROR (@notes, 0, 1) WITH NOWAIT
						RAISERROR (@excludedProviders1, 0, 1) WITH nowait
				END TRY
				BEGIN CATCH
					-- Add exclusion
					BEGIN TRY
						SET @notes = 'NPI ' + ISNULL(@npi,'') + ' excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD ('
									+  CONVERT(VARCHAR(10), ISNULL(@inp_partition_id,0)) + ') ' + ISNULL(ERROR_MESSAGE(), 
									
								'');
						EXECUTE dbo.usp_DevOps_Add_Exclusion_Mod
							@ExcludedId = @ProviderID
							, @ExtractType = @inp_extract_type
							, @notes = @notes;
							SET @excludedProviders2 = @excludedProviders1+2
                          	RAISERROR (@excludedProviders2, 0, 1) WITH NOWAIT
                            RAISERROR (@notes, 0, 1) WITH NOWAIT
                            

As you can see the Notes can't be null -I take every possible precaution against NULLs.

Also none of the RAISERROR messages are outputted and I don't understand why.

Can someone please explain this to me?

Thanks

SQL Server | SQL Server Transact-SQL
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.