Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXEC and return values

Status
Not open for further replies.

Neilf

Technical User
May 15, 2001
22
GB
I've a large dynamic sql statement built in asp. I need to return an error (or anything) from within the exec sql statement. I've tried as shown below but return does not work within the string, and @@ERROR outside the exec statement reports no errors. I've been looking at the forum and the usual answer seems to be to use sp_executesql - in this case, is this possible - can the sql string be concatenated in the same way as with exec(str1+str2)? This must be simple surely?! Thanks in advance.

The sql:
CREATE PROCEDURE usp_MyProc
@strsql1 varchar(8000),
@strsql2 varchar(8000)
AS
EXEC (@strsql1 + @strsql2 +
'IF @@ERROR=0
BEGIN
COMMIT TRANSACTION
RETURN @@ERROR
END
ELSE
BEGIN
ROLLBACK TRANSACTION
RETURN @@ERROR
END ')
GO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top