NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

Using SQL Server for Date Processing

Written by Eric Smith, Northstar Computer Systems LLC

As you learned in an earlier tip, ASP is slow when it comes to formatting text. In addition, it has few functions for manipulating dates. For this reason, I decided to let SQL Server handle some of my date work in a page I built listing books I’ve written. Here’s the page in question:

<a href="http://www.northcomp.com/res_bookstore.asp">http://www.northcomp.com/res_bookstore.asp</a>

And here’s the stored procedure I used:

CREATE procedure sp_RetrieveBookList
As
SELECT B.pkBookID, B.Name, B.Description, B.ISBN,
'Publication Date: ' + DateName(month, B.PubDate) + ' ' + Cast(Year(B.PubDate) As varchar(4)) As DatePublished,
'/pics/book_' + B.ISBN + '.gif' As BookGraphic,
'<a href="' + RTrim(S.URL) + '">' + RTrim(S.Name) + '</a>' As WebSite
FROM tblBooks B, tblSites S
WHERE b.fkSiteID = S.pkSiteID
Order By B.PubDate Desc
We use SQL Server’s built in functions for extracting the month name and year of the publication date. Instead of returning those values, we put them together with the text we need and return the whole thing as a single field. We also stitch the ISBN number with a directory and a file extension to create the local URL to point to the book cover graphic. Finally, we return the support web site name and URL together as a single field.

Note that we used a Cast function around the result of the Year function. This is because SQL Server assumes that since you are adding a string (the month name and space) to a number, you must want to convert the whole thing to a number. This causes an error, but using the Cast function eliminates the problem.

If you’re working with an affiliate program, such as one run by online bookstores, you could easily create multiple URLs using the book’s ISBN number and the affiliate URL provided by your bookstore. Again, leave the string manipulation on the server, where it will run faster.

Keywords: [ Uncategorized ASP Tips ]

Publication Date: 4/1/2000