Practice: Create a New Stored Procedure to Meet a Business Need
As an illustrative example, let's say that we are next asked
by the accounting department of our publishing organization for information to
meet a recurring business need. Accounting needs a crosstab report that
summarizes, from the Pubs database, quarterly sales volumes by sales year.
The information consumers from whom we gather the business
requirements state that the report will become a recurring requirement, and
will be run frequently to update quarterly volumes that, in our business, are
subject to adjustments due to returns and the like. Our developers have the
same restrictions that we mentioned in our first example with regard to the MS
Access connection being their only connection to the database.
The query required to fill the requirement will be a likely
candidate for a Stored Procedure, at least as one means of helping the
information consumers to meet their stated objectives. Once we create such a Stored
Procedure, we can generate the report prospectively at any time, with the
click of a mouse.
Let's meet the needs of the information consumers by taking
the following steps:
From the Query
window, where we left MS Access in our last exercise, click New atop
Query dialog appears.
View, once again.
to dismiss the empty Show Table dialog box that appears.
will use the Pass-Through query option as a conduit, once again, through
which to send a CREATE PROCEDURE statement that includes the query we
need to generate the report for the information consumers. Through this channel,
we will again communicate syntax that the targeted database server understands.
--> SQL Specific --> Pass-Through on the Query menu, as we
did in the earlier section.
The SQL Specific editor appears.
Click the Properties
icon atop the view, again as we did earlier.
The Query Properties page opens. This time, we will
assign connection information for the back-end server using the data source we
created in the first part of our exercises, Pubs_DB.
the ellipses icon ("...") that appears on the right side of the ODBC
Connect Str box on the Query Properties page, as we did earlier.
Data Source dialog appears, defaulted to the File Data Source tab.
Click the Machine
Data Source tab.
the Pubs_DB data source we created in the first section, as shown in Illustration
Illustration 27: Select the Pubs_DB Data Source
On the Connection
String Builder message box that next appears, click the answer you gave
earlier, in our initial response to its question regarding the storage of the
before, I clicked Yes here, as I am in a development environment with
minimal risk involved in storing a password in the connection string. Please
see the warning in the first section of this article regarding doing so in your
We are returned to the Query
Properties page, where we see the new string specification appear in the ODBC
Connect Str box, as we noted in the first section of the article.
Another property we need to consider, again because it is of
significance within our intended use of the Pass-Through query channel,
is the Returns Records setting. This time, we will set it to No,
as shown in Illustration 28.
Illustration 28: The Properties Page, with Our New Settings
We will be writing a one-time CREATE PROCEDURE
statement, containing the query necessary to generate the report we have been
tasked to create, to place the custom Stored Procedure on the back-end
SQL Server. Then, anytime the data needs to be generated, we can execute the Stored
Procedure to obtain updated information for our information consumers. No
recordset will be returned from the CREATE PROCEDURE statement,
therefore Return Records is appropriately set to No.
Close the Query
returned to the SQL Pass-Through Query window.
now ready to create a back-end Stored Procedure.