ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @
What is and Why Do I Need It?

HTTP Status Codes
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Date Delimiter for Access and SQL Server

As most ASP developers quickly discover, Microsoft's two most popular databases (Access and SQL Server) implement SQL differently. The most significant difference for many users is the difference in date delimiter characters. Access likes # while SQL Server expects '. This can make writing a query difficult when you're not sure what platform it'll end up running on or you want it to run on both.

This tip will show you how to determine, from an existing connection, what delimiter you should use. This function checks for Access and if it finds it sets the delimiter to #. If it doesn't it defaults to ' for SQL Server.

' This function takes an open ADODB.Connection object and will
' return the appropriate date delimiter to be used for queries.
' Only Access is checked for... ' is returned o/w. (SQL Server)
Function DateDelimiter(ByRef cnnOpenConnectionObject) ' As String
	Dim strDBMSName
	Dim strDateDelimiter
	strDateDelimiter = "'"
	strDBMSName = cnnOpenConnectionObject.Properties("DBMS Name").Value
	If InStr(1, strDBMSName, "access", 1) Then strDateDelimiter = "#"
	If InStr(1, strDBMSName, "jet", 1) Then strDateDelimiter = "#"
	DateDelimiter = strDateDelimiter
End Function

This allows you to write code like this that will run against either database without any changes.

' Assuming there's an open connection named cnnOpenConnection,
' the following will produce the appropriate SQL query for
' either Access or SQL Server without any code changes!
Dim strDD
Dim strSQL
strDD = DateDelimiter(cnnOpenConnection)
strSQL = "SELECT * FROM table_name " & _
	"WHERE date_field < " & strDD & Now() & strDD & ";"

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers