- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The value returned from a stored procedure call is always an integer, so naming it a message (@msg) is misleading. If there's no explicit return value, the default is zero. So, acting on a zero value means procedures are explicitly returning some other integer to signal something. All around a bad idea. That's what explicitly named OUTPUT parameters (which can be of any type) are for.
Admin
They declare '@msg' as VARCHAR(30), but then say, when converting '@result' to a string, it's a VARCHAR(10)? Sounds like copy-paste ("vibe") programming.
Admin
By convention, the return value from a stored procedure is a status indicator, with zero meaning "Success" and non-zero indicating some kind of error. As @MplsSQLDevGuy says, if you want to return values to a variable, you use output parameters.
And, yes, this should have been
exec @status = do_something @param1 = ... if @status != 0 ...
Admin
also let's hope that app has at most a single user because there is a race condition between the query and the get_last_message call
Admin
Plot twist: maybe the race condition is what was being debugged in the first place?