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
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
Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...
An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...
Free CDs Offer Fundamental Content for IT Pros Are you up to speed on the latest technologies and solutions? Don't miss out on your chance to get up to speed quickly on fundamental, in-depth information on some of the hottest topics in our library of content.
Let Your Users Reset Their Own Passwords: Free Download Try a 30 day free trial of Desktop Authority Password Self-Service – it provides an easy-to-use, robust system for allowing users to reset their own forgotten passwords or locked accounts.
Get Windows IT Pro & Mark Minasi’s Favorite Power Tools Guide Order Windows IT Pro now and get "More of Mark Minasi's Favorite Power Tools"--a in-depth guide to the most useful Windows commands --FREE with your paid order! Subscribe today, and save 58% off the cover price!
Deep Dive into VMware vSphere, eLearning Series Join John Savill to explore the major functionality capabilities of the vSphere virtualization platform, including identification of the changes from ESX 3.5.
I would be interested in any test results you perform in the future.
Paul Limoges March 21, 2000