Hi all, I know that it's fairly trivial to capture SQL error conditions (i.e. constraint violations, etc) by using code similar to:
SELECT @m_error = @@Error  IF @m_error <> 0 GOTO ErrorHandler
SET @TraceMsg = 'Rebuilt new index for ' + CONVERT(varchar(10), @CreateDate, 101) + ' (' + @RowCount + ' component stocks added)'
EXECUTE [dbo].[tracelog] 1, 'Index', 'sp_Rebuild_CurrentList',  @TraceMsg

    	SELECT @func = Object_name(@@Procid)
    	EXECUTE [dbo].[ErrorHandler] @m_error, 'Index sp', @func
But what about warnings? I would like to trap for warnings such as
Warning: Null value is eliminated by an aggregate or other SET operation.
and write when this happens to a trace file.

Of course, another alternative would be to catch the problems as they are added to the database, but I don't have control over the input database, so would have to check it prior to using it, and that's a bit more effort than necessary for this particular project - since, however, I have run across the desire to capture warnings in the past, I must pose the question

Any ideas? Anyone have a need to capture warnings of this type before?