Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MSDN says sp_executesql returns code values 0 on success and any other non-zero value on failure. How do I catch it in a variable? A simple example please.

Also, can it be gotten in MSSQL 2005 just the way I described?

Regards!
Posted
Comments
RedDk 1-Aug-15 20:06pm    
sp_executesql ... used here:

http://www.codeproject.com/Articles/36584/How-To-Store-Any-File-into-SQL-Database

Can't for the life of me understand what you mean by "catch it in a variable". But you refer to return code 0, so you you must know something, right?

1 solution

SQL
declare @ret as integer;
exec @ret = sp_executesql .......;
 
Share this answer
 
Comments
Wendelius 1-Aug-15 14:04pm    
Short and simple, 5.
DamithSL 1-Aug-15 14:18pm    
Thank you, Mika
priyamtheone 2-Aug-15 11:39am    
Oh, it's as simple as that! Wrote the same code last day but didn't work, and I had to post this silly question over here. Later on found out a syntax error in the query statement that was causing the headache. Anyways, it's never bad to review simple things in times. Thanks DamithSL for re-teaching the nursery lesson. :-)
DamithSL 2-Aug-15 11:46am    
don't worry we all in same boat ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900