Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

Create stored procedure Expand / Collapse
Author
Message
Posted Wednesday, March 16, 2011 7:30 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
Thanks for the interesting question.
Post #1079427
Posted Wednesday, March 16, 2011 11:30 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, June 30, 2014 2:51 AM
Points: 1,971, Visits: 369
Another "funny" thing is that BEGIN...END does not define the body of the procedure. You can have multiple BEGIN...END in the body of a procedure, like this:
create proc test
as
begin
select 1
end
begin
select 2
end

Executing "test" will return two recordsets.

A procedure can have an empty body, but BEGIN...END cannot be empty.


This one is pretty interesting. I really didn't know that by adding Begin, End (twice or more), we can return 2 recordsets. But I dont think this type of proc can ever be used.

Has anybody tried using sp_spaceused (returns 2 recordsets) in a select query ? Its just not possible.
Post #1079468
Posted Thursday, March 17, 2011 12:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:48 AM
Points: 13,261, Visits: 10,138
Nice question, thanks.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1079483
Posted Thursday, March 17, 2011 1:50 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 19, 2011 1:59 AM
Points: 1,042, Visits: 234
I agree with Ron.

This question made us look into the basics of naming conventions.

Thanks for the question.
Post #1079507
Posted Thursday, March 17, 2011 2:41 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, July 17, 2014 4:47 AM
Points: 3,352, Visits: 1,480
Here's where it's useful. If you want an alternative to the DROP and CREATE method of maintaining stored procedure scripts - which would overwrite metadata about when a procedure was first created - you can use this:

IF OBJECT_ID ( '[dbo].[NewProcedure]', 'P' ) IS NULL 
BEGIN
EXEC ('CREATE PROCEDURE [dbo].[NewProcedure] AS')
END
GO
ALTER PROCEDURE [dbo].[NewProcedure]
-- Procedure code goes here

Just an idea.
Post #1079520
Posted Thursday, March 17, 2011 2:52 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Tuesday, July 1, 2014 9:43 PM
Points: 697, Visits: 155
You can not use any special character as a first later of procedure name except _ .
Post #1079522
Posted Thursday, March 17, 2011 2:57 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 8:03 AM
Points: 1,403, Visits: 1,808
amit_adarsh (3/17/2011)
You can not use any special character as a first later of procedure name except _ .


That is because they are not supported by the naming conventions for identifiers. Please go back to the 1st page of the discussion where I have explained why the SQL Server allows you to create this particular stored procedure.


Thanks & Regards,
Nakul Vachhrajani.
http://beyondrelational.com/modules/2/blogs/77/nakuls-blog.aspx
Be courteous. Drive responsibly.

Follow me on
Twitter: @sqltwins
Google Plus: +Nakul
Post #1079523
Posted Thursday, March 17, 2011 3:28 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 9:53 AM
Points: 1,713, Visits: 6,243
ziangij (3/16/2011)I really didn't know that by adding Begin, End (twice or more), we can return 2 recordsets.


You don't need multiple begin/end pairs to return 2 recordsets.

create proc test
as
begin
select 1
select 2
end

or

create proc test
as
select 1
select 2

will do just as well.

We make regular use of procedures returning multiple recordsets. Using ADO you just use NextRecordSet to get at the data.
Post #1079530
Posted Thursday, March 17, 2011 3:56 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 7:31 AM
Points: 377, Visits: 3,060
Bala' (3/16/2011)
Its not really adding any value..


There is actually quite a lot of value. When creating a system in a team environment, it allows the db developer to create all the procedure stubs initiallly even though they may not return any values. In turn, this allows the front end coders get on with coding the data access layer to an extent. The db developer can then continue addig the function bodies without other developers screaming at him to hurry up.

You may not see the value, but it is there for somebody.
Post #1079536
Posted Thursday, March 17, 2011 7:21 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232, Visits: 1,046
rjohal-500813 (3/17/2011)
Bala' (3/16/2011)
Its not really adding any value..


You may not see the value, but it is there for somebody.


I would have to agree with that. Somebody out there sees all kinds of value in SQL developers and DBA's know the minimum amount of code required to create Procedures and Functions. Most likely why it is on the Certification exams.
Post #1079626
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse