Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Is this a best practice for Stored Procedures?

Author  Topic 

trondaron
Starting Member

13 Posts

Posted - 2009-07-13 : 20:36:03
My partner is ending all stored procedures (that dont return record sets) with the line:
SELECT 1

Example:
CREATE PROCEDURE [dbo].[Transfer_Insert] 
@clientID INT,
@consigneeID INT,
@statusID INT,
@receiptID INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO dbo.Transfer (
clientID,
consigneeID,
statusID
) VALUES (
@clientID,
@consigneeID,
@statusID
)

SET @receiptID = SCOPE_IDENTITY();

SELECT 1
END


What positive effect does this have?
At the moment it's causing problems when I nest it in another stored procedure as it appears to the initial calling function that a record set containing 1 is returned.

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-13 : 21:03:54
has no benefit. should not do that
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-07-14 : 10:44:57
I think your partner means to RETURN 1, not SELECT 1.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

trondaron
Starting Member

13 Posts

Posted - 2009-07-14 : 13:15:07
Well I worked up the nerve to ask, and his answer to why he ends the queries with that:

"I don't know"

Awesome...
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-14 : 14:02:50
I agree with Blindman it should probably be RETURN.. But I wouldn't retutrn 1 I'd return 0 (Zero) or @@ERROR or something meaningfull. Although, you can use the RETURN statement to do other things, to me anything other than zero means someting did not go correctly.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-07-14 : 15:15:28
quote:
Originally posted by trondaron

Well I worked up the nerve to ask, and his answer to why he ends the queries with that:

"I don't know"

Awesome...


Cargo-cult programming.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-14 : 15:24:02
It is funny - when he don't know how then should we know


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-07-15 : 09:41:51
What's funny is that we do know.
He is mistakenly using SELECT 1 instead of RETURN 1 (or zero), because he is clueless as to the purpose.
He is just blindly copying what he thinks he has seen others do, without any attempt at understanding. Hence, Cargo Cult Programming.
________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-15 : 11:01:48
I think we don't know.
We assume...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-07-15 : 13:39:06
I know I do know.

I'm just arrogant that way. Care to place a bet on it?

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-15 : 14:51:36
No - thank you


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

trondaron
Starting Member

13 Posts

Posted - 2009-07-15 : 18:36:36
Seeing as I'm noticing pieces of code that look like they copy/pasted from mine, and other pieces that _are_ copy/pasted from mine. I'd say this is a safe bet.

Error trapping in his code that traps for exceptions that can't happen, looks just like some code I wrote a few days ago...

Go to Top of Page
   

- Advertisement -