T-SQL: How to return 0 rows in from stored procedure, and how to use XACT_ABORT and TRY/CATCH?

To return 0 rows, you can do: SELECT TOP 0 NULL AS MyValue Personally, I'd use an OUTPUT parameter for this sproc to return the ID back out instead of returning a resultset - that's just my preference though. Then just set that output parameter to e.g. -1 as default to indicate nothing done.

Thanks for the fast response! I'm getting a 0 result set back from that :) But any idea why after EXEC MySP why @@ROWCOUNT = 1? – Michael Waterfall Aug 18 '10 at 10:32 EXEC @ret = MySP; SET @rows = @@ROWCOUNT; SELECT 'Rows' = @rows returns 1 as then number of rows!?

– Michael Waterfall Aug 18 '10 at 10:33 Ah, am I right in thinking @@ROWCOUNT is only changed for statements that affect rows (i.e. INSERT or UPDATE)? – Michael Waterfall Aug 18 '10 at 11:04 @Michael Waterfall, run print 'wow wee!

'; select @@ROWCOUNT, you'll get a row count of zero. – KM. Aug 18 '10 at 12:17.

This is how I'd do it: CREATE PROCEDURE YourProcedure AS ( @NewMyValue int OUTPUT --Output parameter was set to a default of NULL SET @return = 2; -- Fail error END COMMIT TRANSACTION --Output parameter was set to a default of NULL SET @return = 1; -- General error END CATCH -- End transaction and return RETURN @return; GO.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions