<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bacon Bits: &#187; SQL Server</title>
	<atom:link href="http://datapigtechnologies.com/blog/index.php/tag/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://datapigtechnologies.com/blog</link>
	<description>A DataPig Technologies Blog</description>
	<lastBuildDate>Tue, 07 Feb 2012 16:56:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Running a SQL Stored Procedure from Excel (No VBA)</title>
		<link>http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/</link>
		<comments>http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/#comments</comments>
		<pubDate>Tue, 04 May 2010 18:02:39 +0000</pubDate>
		<dc:creator>datapig</dc:creator>
				<category><![CDATA[Excel Tips and Tricks]]></category>
		<category><![CDATA[MS Query]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Power Tips]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/</guid>
		<description><![CDATA[We all know we can use MS Query to get data from a SQL server. Typically though, we pull from a Table or a View. Well in some organizations, the IT department wants all interaction with the server to be done through Stored Procedure. This adds a level of risk management and makes the DBAs [...]
Related posts:<ol>
<li><a href='http://datapigtechnologies.com/blog/index.php/running-an-access-parameter-query-from-excel/' rel='bookmark' title='Running an Access Parameter Query from Excel'>Running an Access Parameter Query from Excel</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/filter-on-selection-in-excel/' rel='bookmark' title='Filter on Selection in Excel'>Filter on Selection in Excel</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/' rel='bookmark' title='Passing Multiple Values to One Parameter'>Passing Multiple Values to One Parameter</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/avoiding-data-cut-off-in-excel/' rel='bookmark' title='Avoiding Data Cut-Off in Excel'>Avoiding Data Cut-Off in Excel</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/protect-worksheet-structure-with-array-formulas/' rel='bookmark' title='Protect Worksheet Structure with Array Formulas'>Protect Worksheet Structure with Array Formulas</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>We all know we can use MS Query to get data from a SQL server. Typically though, we pull from a Table or a View. Well in some organizations, the IT department wants all interaction with the server to be done through Stored Procedure. This adds a level of risk management and makes the DBAs feel better.</p>
<p> </p>
<p>So today, I&#8217;ll show you how to easily make Excel run a Stored Procedure to get data.</p>
<p> <span id="more-1965"></span></p>
<p><strong>Step 1:</strong> Data tab &#8211; &gt; From Other Sources -&gt; From SQL Server</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL1.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 2:</strong> Enter Credentials. Your server name can be an IP address</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL2.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 3:</strong> Choose any old table or view. Pick a small one because we&#8217;ll discard it later anyway.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL3.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 4:</strong> Excel will pop up the Import Data dialog box. Click Properties here (NOT THE OK BUTTON).</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL4.png" alt="" /></p>
<p> </p>
<p><strong>Step 5:</strong> Click on the Definition tab. There, change Command Type to SQL, and then enter your Stored Procedure name in the Command Text input.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL5.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 6:</strong> Excel complains about something….blah…blah…blah. Click Yes – (as in yes I know what I&#8217;m doing).</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL6.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 7:</strong> Excel will activate the Import Data dialog box again. This time click OK to fire the Stored Procedure and return the results.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL7.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 8: </strong>Marvel at your results</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL8.png" alt="" /></p>
<p> </p>
<p> </p>
<p><span style="font-size:12pt"><strong>Notes:<br />
</strong></span></p>
<ol>
<li>Excel will fire the Stored Procedure each time you &#8220;Refresh&#8221;</li>
<li>
<div>If you have to pass a parameter, you can enter it in the command text like this:</div>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL9.png" alt="" /></p>
<p> </li>
<li>If you have to pass dynamic parameters you&#8217;ll have to turn to VBA. <a href="http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel-with-dynamic-parameters/">See this post</a>.</li>
<li>I assume you can do this with ORACLE databases too.</li>
<li>I&#8217;ve yet to test whether this will fire a Stored Procedure that doesn&#8217;t return data. In other words, Stored Procedures that perform Insert, Update or Delete actions. I assume that if you can, there is the possibility of updating SQL from Excel through a simple connection. Pretty cool.</li>
</ol>
<p>Related posts:<ol>
<li><a href='http://datapigtechnologies.com/blog/index.php/running-an-access-parameter-query-from-excel/' rel='bookmark' title='Running an Access Parameter Query from Excel'>Running an Access Parameter Query from Excel</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/filter-on-selection-in-excel/' rel='bookmark' title='Filter on Selection in Excel'>Filter on Selection in Excel</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/' rel='bookmark' title='Passing Multiple Values to One Parameter'>Passing Multiple Values to One Parameter</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/avoiding-data-cut-off-in-excel/' rel='bookmark' title='Avoiding Data Cut-Off in Excel'>Avoiding Data Cut-Off in Excel</a></li>
<li><a href='http://datapigtechnologies.com/blog/index.php/protect-worksheet-structure-with-array-formulas/' rel='bookmark' title='Protect Worksheet Structure with Array Formulas'>Protect Worksheet Structure with Array Formulas</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

