Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


March 20, 2000

Using Stored Procedures to Build HTML Option Lists


RSS
Subscribe to Windows IT Pro | See More Active Server Pages (ASP) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

I'm part of a team working on an Internet site that uses lots of SQL Server tables to drive HTML Select lists. On many pages, for example, users can enter a country or state by simply selecting the entry from a list. We used Active Server Pages (ASP) to generate the lists, as most applications do, and eventually created functions to generate the list and stored those functions in an Include file. However, ASP requires extra time on the server to load and process the Include file. In addition, you must use the entire Include file every time you want to create a Select list from a table.

On the way to a client site recently, I had an idea. What if we put the functions in a stored procedure instead of an Include file and let the stored procedure build the option list for the Select statement? I began experimenting. The following code, version 1 of this approach, generates a record set formatted correctly for an option list. (I'll explore a more-detailed version in the next couple of weeks as our testing evolves.)

First, I use T-SQL's concatenation feature to create a Select statement that builds the option list from the generated the record set:

Alter Procedure "getOptionListStates"
	As
	select ('') 
	as OptionList from states

Executing the getOptionListStates stored procedure results in this record set:


	
	
	

You could also generate the option list directly in the database.

The next step is to modify the stored procedure to return a single variable that contains the complete option list. You then simply feed that return variable back to the HTML Select statement.

Our team hasn't compared the stored procedure approach's performance with the ASP approach's. That step is next. What I find most interesting about this technique, though, is being able to use SQL Server to automatically generate part of the HTML we normally put in our ASP code. This mixed approach to building ASP code should result in a solution that performs better and is more flexible than pure ASP. For instance, if you create a flexible stored procedure that builds a Select option list, you can easily use that stored procedure from any number of applications, even applications on different servers. That's hard to do when you bury all of your code in an Include file.

End of Article



Reader Comments
ASP/SQL has always been great for our applications. Using stored procedures would be a great idea if these queries are used frequently. The performance gain would be from the SQL end of things, since the procedure is already stored. I am not sure if there would be any ASP performance gain, since the call for the query is still being loaded. The only difference is the SQL is returning the results faster with the stored procedure. We have developed a multi-language site, where the SQL database drives the ASP pages. The majority of the ASP pages dynamically load the page according to the users selected language.
I would be interested in any test results you perform in the future.

Paul Limoges March 21, 2000


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Related Events SQL Server Unleashed EMEA

WinConnections and Microsoft® Exchange Connections

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

SQL Server and Database eBooks Safeguarding Your Windows Servers

SQL Server Administration for Oracle DBAs

Taking Control: Monitoring the Windows Platform Proactively

Related SQL Server and Database Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement