Groups | Blog | Home
all groups > sql server programming > august 2003 >

sql server programming : sproc output


Hassan
8/3/2003 8:41:17 PM
I need to perform some SQL based upon the output of another system sproc.

So if the sproc returns 1 row, then i need to do something, if not then dont
do anything..

How can i write a TSQL for that such as

exec sprocA
if ( # of rows returned is 1 ) then print ' Go ahead '
else print ' No records returned '

P.S. I cannot modify sprocA

Dan Guzman
8/3/2003 10:51:25 PM
You might try:

EXEC sprocA

IF @@ROWCOUNT = 1
PRINT ' Go ahead '
ELSE
PRINT ' No records returned '

Note that this will only work if the last statement in the proc is the
SELECT because subsequent statements in the proc may change the
@@ROWCOUNT value.

--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

[quoted text, click to view]

AddThis Social Bookmark Button