Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

SQL Server
SQL Server Automating Administration
SQL Server Full Text Searching
SQL Server Installing
SQL Server Selecting XML Data
SQL Server XSL Stylesheets
SQL Server Stored Procedures
SQL Server XDR Schemes
SQL Server Indexed Views
SQL Server Introduction
SQL Server Data Statements
SQL Server SELECT Statement
SQL Server Modification Statements
SQL ServerTransaction Statements
SQL Server Schema Statements
SQL Server XML Introduction
SQL Server XML Templates

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


SQL Server 2000 And XML Part 4 - Calling Stored Procedures In URLS


Previoushome Next






SQL Server 2000 And XML Part 4 - Calling Stored Procedures In URLS


 


A D V E R T I S E M E N T


Also, we really don't want to have a user learn the SQL language just to display some data in a browser. This is where stored procedures can be very useful.

Using a stored procedure we can use the same SELECT statements that we entered into the URL of the browser and reduce the length of the URL that needs to be entered. We can then just execute the stored procedure in the URL instead of having to specify the entire SELECT statement.

As we have discovered in past chapters, using a stored procedure is more efficient because it is optimized in SQL Server and is compiled and cached on its first execution. This, and the fact that we can easily write more complex queries in a stored procedure, makes using them ideal.

When we execute a stored procedure in the URL we need to specify the EXECUTE keyword and the stored procedure name, just as we would in the Query Analyzer. An example of this is shown:

http://localhost/htData?SQL=EXECUTE+up_select_xml_hardware&XSL=
Hardware.xsl&ContentType=Text/HTML&Root=Hardware

The only difference between this URL and the last is that this URL executes a stored procedure instead of the SELECT statement. All other keywords such as SQL, XSL, ContentType, and Root must still be specified.

Try It Out - Hardware Select Stored Procedure

Let's put this knowledge to use by creating a stored procedure to select the hardware data that is required by our Hardware.xsl template.

1. The stored procedure that we want to create is listed below. Enter the code for this stored procedure in the Query Analyzer and execute it:

CREATE PROCEDURE up_select_xml_hardware AS

SELECT Manufacturer_VC, Model_VC
FROM Hardware_T
FOR XML AUTO

GO

GRANT EXECUTE ON up_select_xml_hardware TO [Hardware Users]

2. To test this stored procedure enter the following URL in your browser:

http://localhost/htData?SQL=EXECUTE+up_select_xml_hardware&XSL=
Hardware.xsl&ContentType=Text/HTML&Root=Hardware

The results of executing this stored procedure should be the same as you saw in the last exercise. The only difference here is that we have just executed a stored procedure in the URL instead of a SELECT statement.

How It Works - Hardware Select Stored Procedure

This stored procedure looks just about like every other SELECT stored procedure that we have created. We start the stored procedure by specifying the CREATE PROCEDURE statement followed by the stored procedure name and the AS keyword.

Then we specify the SELECT statement, which selects two columns from the Hardware_T table. We have also included the FOR XML clause so the results of the stored procedure will be returned as XML data to the browser:

SELECT Manufacturer_VC, Model_VC
FROM Hardware_T
FOR XML AUTO

We specify the GO command to have the Query Analyzer create this stored procedure before we grant permissions on it to the hardware users role:

GO

GRANT EXECUTE ON up_select_xml_hardware TO [Hardware Users]

It is important to note that you cannot execute just any stored procedure in a URL. It must be a SELECT stored procedure, and it must return XML data. The SELECT statement must, therefore, contain the FOR XML clause.

Stored Procedure Parameters

Now that we know we can execute a stored procedure in the URL, it stands to reason that we could also execute a stored procedure that accepts parameters. This is true, and not as difficult as it may seem. This section will walk through a couple of examples that illustrate executing stored procedures that accept parameters, and point out what is needed to pass parameters to a stored procedure.

When we execute a parameterized stored procedure in the Query Analyzer, we simply specify the EXECUTE statement followed by the stored procedure name and any parameters that it might expect. Looking at the following example, the up_parmsel_assigned_system stored procedure accepts one parameter, the Employee_ID. Execution of this code produces the desired results:

EXECUTE up_parmsel_assigned_system 1

Assuming this stored procedure returned the results as XML data we would execute this same stored procedure in a browser using the following code fragments in place of the SQL statements.

The first code fragment demonstrates executing this stored procedure by only passing the parameter as we do in the Query Analyzer:

EXECUTE+up_parmsel_assigned_system+1

The second code fragment demonstrates specifying the parameter name and its value. When using this method the parameter name specified must exactly match the parameter name in the stored procedure:

EXECUTE+up_parmsel_assigned_system+@Employee_ID=1

Let's assume for a moment that we have a stored procedure named up_parmsel_employee. This stored procedure expects the employee's last name as the first input parameter and the employee's location ID as the second input parameter. To execute this stored procedure in a URL we would specify the code as shown in the following code fragments in place of the usual SQL statements.

The first example simply specifies the parameter values. Notice that we have included a comma between the two input parameters and, since the first parameter is a string value, it has been enclosed in single quotes:

EXECUTE+up_parmsel_employee+'Willis'+,+1

The second example specifies the parameter names and parameter values. Again we have enclosed the first parameter in single quotes and used a comma to separate the parameters:

EXECUTE+up_parmsel_employee+@Last_Name_VC='Willis'+,+@Location_ID=1

Try It Out - Parameterized Stored Procedure

Now that we know that we can execute a parameterized stored procedure in a URL we want to create a stored procedure that accepts parameters so we can experience this first hand. The stored procedure that we want to create should select most of the columns in the Hardware_T table. The input parameter to this stored procedure will be the Hardware_ID, which will point to the row of data that we want to select.

1. The code for this stored procedure is listed below. Enter this code in the Query Analyzer and execute it:

CREATE PROCEDURE up_parmsel_xml_hardware 
@Hardware_ID INT AS

SELECT Manufacturer_VC, Model_VC, Processor_Speed_VC,
Memory_VC, HardDrive_VC, Sound_Card_VC,
Speakers_VC, Video_Card_VC, Monitor_VC, 
Serial_Number_VC, Lease_Expiration_DT,
CD_Type_CH

FROM Hardware_T
JOIN CD_T ON Hardware_T.CD_ID = CD_T.CD_ID

WHERE Hardware_ID = @Hardware_ID

FOR XML AUTO

GO

GRANT EXECUTE ON up_parmsel_xml_hardware TO [Hardware Users]  

2. Before you execute this stored procedure in a browser, you will need to obtain a valid number for the hardware ID. You can do this by right-clicking on the Hardware_T table in the Object Browser of the Query Analyzer and choosing Open from the context menu.

3. Once you have a valid hardware ID enter the following URL in your browser, replacing the hardware ID specified with one that is valid in your Hardware_T table:

http://localhost/htData?SQL=EXECUTE+
up_parmsel_xml_hardware+1+&Root=Hardware

You should see results similar to those shown in the next figure. Notice that we have not used an XSL stylesheet to format the data in this example, so it is just returned as XML data:

4. You can further test this stored procedure and see the different results by substituting the @Hardware_ID parameter with different values. If you use a value that does not exist, you will not receive an error message but just an empty XML document, as shown in the next figure:

 



Be the first one to comment on this page.




  SQL Server eBooks

No eBooks on SQL Server could be found as of now.

 
 SQL Server FAQs
More Links » »
 
 SQL Server Interview Questions
More Links » »
 
 SQL Server Articles
More Links » »
 
 SQL Server News
More Links » »
 
 SQL Server Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: SQL Server 2000 And XML Part 4 - Calling Stored Procedures In URLS, SQL Server, SQL Server, SQL Server Tutorial, SQL Server tutorial pdf, history of SQL Server, SQL Server Administration, learn SQL Server

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.