<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQL Server Stored Procedures &#8211; Fundamentals</title>
	<atom:link href="http://www.sql-server-performance.com/2003/stored-procedures-basics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/</link>
	<description>SQL Server Performance Tuning</description>
	<lastBuildDate>Fri, 17 May 2013 13:31:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: toughdeep</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-2084</link>
		<dc:creator>toughdeep</dc:creator>
		<pubDate>Mon, 23 Jul 2012 12:42:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-2084</guid>
		<description><![CDATA[Thanks but one important part not mentioned here is &quot;how to modify the stored procedure and save it as the same stored procedure?&quot;
Right click on the edited query editor page and execute it to save the changes to the stored procedure.(when you change and try to close it prompts you to change as a query, but not as the stored procedure.]]></description>
		<content:encoded><![CDATA[<p>Thanks but one important part not mentioned here is &#8220;how to modify the stored procedure and save it as the same stored procedure?&#8221;</p>
<p>Right click on the edited query editor page and execute it to save the changes to the stored procedure.(when you change and try to close it prompts you to change as a query, but not as the stored procedure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Billy Howell</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-2001</link>
		<dc:creator>Billy Howell</dc:creator>
		<pubDate>Thu, 14 Jun 2012 19:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-2001</guid>
		<description><![CDATA[Unfortunately, far more complex stored procedures have been written, Bryan, but I will walk through it quickly.
The first two lines are an example of how to declare variables in your stored procedure. DECLARE...uh, declares the variable.  SET assigns the variable with a value.  You can also do something like SELECT 1 INTO  FROM .
The block that the first lines belong too just serve as an example.  Other than the variables it is much like this article explained.  Obviously, in the third line, the parameter declaration has values assigned to them.
The second block is searching for an existing version of a stored procedure with the name ‘sproc_insertvendor’.  If it exists, then drop it so that you can create your new one or your new version if you are running this more than once.
Nothing really new in the third block although I would like to add a side note.  To make a parameter optional, you can add a default value (e.g. @countOfPayments INT = 0) which is extremely valuable information to me at least.
The fourth block introduces you to Raiserror.  I don&#039;t personally know if this is built into SQL Server or not, but it is setting the @@error variable.  @@ delineates system or global variables the best I can tell.
Finally, the fifth block is inserting a row as long as the person doesn&#039;t already exist.
One last side note:  try not to write if exists(select *...  If you just wanna know if it exists, if exists(select 1... is more performant and gives you the same information you wanted to know.
Good article, author.  I need to find one for advanced beginners now.]]></description>
		<content:encoded><![CDATA[<p>Unfortunately, far more complex stored procedures have been written, Bryan, but I will walk through it quickly.</p>
<p>The first two lines are an example of how to declare variables in your stored procedure. DECLARE&#8230;uh, declares the variable.  SET assigns the variable with a value.  You can also do something like SELECT 1 INTO  FROM .</p>
<p>The block that the first lines belong too just serve as an example.  Other than the variables it is much like this article explained.  Obviously, in the third line, the parameter declaration has values assigned to them.</p>
<p>The second block is searching for an existing version of a stored procedure with the name ‘sproc_insertvendor’.  If it exists, then drop it so that you can create your new one or your new version if you are running this more than once.</p>
<p>Nothing really new in the third block although I would like to add a side note.  To make a parameter optional, you can add a default value (e.g. @countOfPayments INT = 0) which is extremely valuable information to me at least.</p>
<p>The fourth block introduces you to Raiserror.  I don&#8217;t personally know if this is built into SQL Server or not, but it is setting the @@error variable.  @@ delineates system or global variables the best I can tell.</p>
<p>Finally, the fifth block is inserting a row as long as the person doesn&#8217;t already exist.</p>
<p>One last side note:  try not to write if exists(select *&#8230;  If you just wanna know if it exists, if exists(select 1&#8230; is more performant and gives you the same information you wanted to know.</p>
<p>Good article, author.  I need to find one for advanced beginners now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-1772</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Wed, 21 Mar 2012 23:11:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-1772</guid>
		<description><![CDATA[Hi Tom,
This is the best article I have ever found online.  Your instruction is extremely easy and helpfulfor me to understand and use for my work.
Truly appreciate you!
Best regards,
Patrick]]></description>
		<content:encoded><![CDATA[<p>Hi Tom,</p>
<p>This is the best article I have ever found online.  Your instruction is extremely easy and helpfulfor me to understand and use for my work.<br />
Truly appreciate you!<br />
Best regards,<br />
Patrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cell</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-1746</link>
		<dc:creator>cell</dc:creator>
		<pubDate>Thu, 15 Mar 2012 12:50:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-1746</guid>
		<description><![CDATA[I forgot to thank &quot;Om Mohokar&quot; for his post, cheers mate.]]></description>
		<content:encoded><![CDATA[<p>I forgot to thank &#8220;Om Mohokar&#8221; for his post, cheers mate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Revellant</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-1204</link>
		<dc:creator>Bryan Revellant</dc:creator>
		<pubDate>Tue, 10 Jan 2012 16:52:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-1204</guid>
		<description><![CDATA[Hi Tom,
This was a really informative article for us beginner SQL developers. The procedure was not very complex and easy to understand. I have been studying from a high level SQL developer in order to understand SQL better and he very much confused me with the very advanced code that he was using. Example of more complex code
/*
declare @today datetime
SET @Today = getdate()
EXECUTE sproc_insertvendor @name = &#039;something Else&#039;, @countofpayments = 3, @lastpaydate = @Today, @nextpaydate = @Today, @Comments = null
*/
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE Name = &#039;sproc_insertvendor&#039;)
	DROP PROCEDURE sproc_insertvendor
GO
CREATE PROCEDURE sproc_insertvendor
	@name varchar(200),
	@countOfPayments int,
	@LastPayDate datetime,
	@nextpaydate datetime,
	@comments ntext
AS
	if exists (
		select *
		from vendor v
		where v.name = @name
			)
	BEGIN
		Raiserror(&#039;%s already exists!&#039;,16,2,@name)
	END
	if @@error=0
	BEGIN
		INSERT INTO vendor (Name,CountOfPayments,LastPayDate,NextPayDate,Comments)
		VALUES (@Name,@CountOfPayments,@LastPayDate,@NextPayDate,@Comments)
		SELECT @@Identity
	END
RETURN
GO]]></description>
		<content:encoded><![CDATA[<p>Hi Tom,</p>
<p>This was a really informative article for us beginner SQL developers. The procedure was not very complex and easy to understand. I have been studying from a high level SQL developer in order to understand SQL better and he very much confused me with the very advanced code that he was using. Example of more complex code </p>
<p>/*<br />
declare @today datetime<br />
SET @Today = getdate()<br />
EXECUTE sproc_insertvendor @name = &#8216;something Else&#8217;, @countofpayments = 3, @lastpaydate = @Today, @nextpaydate = @Today, @Comments = null<br />
*/</p>
<p>IF EXISTS (SELECT * FROM SYSOBJECTS WHERE Name = &#8216;sproc_insertvendor&#8217;)<br />
	DROP PROCEDURE sproc_insertvendor<br />
GO</p>
<p>CREATE PROCEDURE sproc_insertvendor<br />
	@name varchar(200),<br />
	@countOfPayments int,<br />
	@LastPayDate datetime,<br />
	@nextpaydate datetime,<br />
	@comments ntext<br />
AS</p>
<p>	if exists (<br />
		select *<br />
		from vendor v<br />
		where v.name = @name<br />
			)<br />
	BEGIN<br />
		Raiserror(&#8216;%s already exists!&#8217;,16,2,@name)<br />
	END</p>
<p>	if @@error=0<br />
	BEGIN<br />
		INSERT INTO vendor (Name,CountOfPayments,LastPayDate,NextPayDate,Comments)<br />
		VALUES (@Name,@CountOfPayments,@LastPayDate,@NextPayDate,@Comments)<br />
		SELECT @@Identity<br />
	END</p>
<p>RETURN</p>
<p>GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Avinash Kumar</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-748</link>
		<dc:creator>Avinash Kumar</dc:creator>
		<pubDate>Thu, 20 Oct 2011 10:18:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-748</guid>
		<description><![CDATA[Hi Tom
Your article are really awesome.actually i was in search for some good articles on stored procedures and finally i got one.
The most important is the simplicity which will be very helpful for the beginners.
Thanks
Avinash]]></description>
		<content:encoded><![CDATA[<p>Hi Tom<br />
Your article are really awesome.actually i was in search for some good articles on stored procedures and finally i got one.<br />
The most important is the simplicity which will be very helpful for the beginners. </p>
<p>Thanks<br />
Avinash</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bhuvan</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-584</link>
		<dc:creator>Bhuvan</dc:creator>
		<pubDate>Sun, 04 Sep 2011 11:21:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-584</guid>
		<description><![CDATA[Hi Tom,
I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of stored procedure and it will help me a lot.
Thank you very much!
Bhuvan]]></description>
		<content:encoded><![CDATA[<p>Hi Tom,</p>
<p>I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of stored procedure and it will help me a lot.</p>
<p>Thank you very much!<br />
Bhuvan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Om Mohokar</title>
		<link>http://www.sql-server-performance.com/2003/stored-procedures-basics/#comment-501</link>
		<dc:creator>Om Mohokar</dc:creator>
		<pubDate>Tue, 02 Aug 2011 16:15:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=436#comment-501</guid>
		<description><![CDATA[creating and calling stored procedure in .net:
create procedure insert1(@userid int,@username varchar(50))
as
begin
insert into emp(id,name)values(@userid,@username)
end
NOTE:(id,name) are the columns of table in which you want to insert data.
CALLING STORED PROCEDURE :
initialize this globally:
public partial class1:class
{
sqlconnection con;
sqlcommand cmd;
}
on page_load():   // write on page load()
{
con=new sqlconnection(&quot;Connection string&quot;);
cmd=new sqlcommand();
cmd.connection=con;
cmd.commandtype=commandtype.stored procedure;
}
on button_click()   // write on insert button_clik event
{
cmd.parameters.clear();
cmd.commandtext=&quot;insert1&quot;;
    // stored procedure name just created.
cmd.parameters.addwithvalue(&quot;@userid&quot;,textbox1.text);
cmd.parameters.addwithvalue(&quot;@username&quot;,textbox2.text);
con.open();
cmd.executenonquery();
messagebox.show(&quot;stored procedure inserted...&quot;);
con.close();
}]]></description>
		<content:encoded><![CDATA[<p>creating and calling stored procedure in .net:</p>
<p>create procedure insert1(@userid int,@username varchar(50))<br />
as<br />
begin<br />
insert into emp(id,name)values(@userid,@username)<br />
end</p>
<p>NOTE:(id,name) are the columns of table in which you want to insert data.</p>
<p>CALLING STORED PROCEDURE :</p>
<p>initialize this globally:<br />
public partial class1:class<br />
{<br />
sqlconnection con;<br />
sqlcommand cmd;<br />
}</p>
<p>on page_load():   // write on page load()<br />
{<br />
con=new sqlconnection(&#8220;Connection string&#8221;);<br />
cmd=new sqlcommand();<br />
cmd.connection=con;<br />
cmd.commandtype=commandtype.stored procedure;<br />
}</p>
<p>on button_click()   // write on insert button_clik event</p>
<p>{<br />
cmd.parameters.clear();<br />
cmd.commandtext=&#8221;insert1&#8243;;<br />
    // stored procedure name just created.<br />
cmd.parameters.addwithvalue(&#8220;@userid&#8221;,textbox1.text);</p>
<p>cmd.parameters.addwithvalue(&#8220;@username&#8221;,textbox2.text);<br />
con.open();<br />
cmd.executenonquery();<br />
messagebox.show(&#8220;stored procedure inserted&#8230;&#8221;);<br />
con.close();<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
