asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

PreviousNext

 

email this FAQ to a colleague

Q: I'd appreciate it if someone could point out what the problem is here?

Microsoft OLE DB Provider for SQL Server error '80040e14'

Line 1: Incorrect syntax near '>'.

sSQL="Select * from Subscribe Date> 08/23/2002"

A: 1: A WHERE clause would help... This is probably the cause for the syntax error.

2: "Date" is a Reserved Word in SQL Server. Enclose in [], or that may result in another syntax error.

3: Once you get the first two fixed, your query will return the wrong result... read on:

You must understand what TYPE of data you deal with - especially with dates - and even more especially when you communicate it between type-different subsystems such as a user and your application and your application to a database via SQL statements.

Understand the difference between a "date" and a "date string". Typically, a "date" typed variable will be stored internally as a floating point number, with the whole number representing the date (typically an offset from some date determined by be 0), and the fraction representing the time of day. A "date string" is just a translation of the date variable to a meaningful format that we can read.

You also need to understand how your expressions are being evaluated, including in a SQL statement. A numeric expression (one that starts with a number or a numeric function and includes numbers and arithmetic operators and numeric functions) will be calculated according to arithmetic rules: 08/23/2002 is a numeric expression, and will be calculated as 8 / 23, and the result divided by 2002. SQL Server may consider the expression an integer expression, in which case you'll get Midnight, January 1, 1900, otherwise it will add 15 seconds and 10 milliseconds for the fraction, i.e. 00:00:15.010 AM on January 1, 1900.

Different systems (and subsystems) format and interpret date strings differently. This can be based on the development environment and coding language, the functions used, a subsystem's configuration (read the SQL Server/Database configuration settings) as well as regional settings on the various computers involved (client PC, application PC/web server, database server, etc.), their respective subsystems, and even specific settings for a particular Web page.

Because there are so many environmental factors involved, it is risky to make assumptions about date formats. You should perform explicit conversion between date variables and their string representation (and back), explicitly specifying what format to use, and always store/manipulate date values in their "native" (internal storage format in a date type variable) form.

Specifically, for SQL Server queries from VBScript, create custom conversion functions to produce and interpret a well defined date string format from your VBScript (in VB, you can use the Format$() function with a format specification, but that is not available in VBScript). Then you tell SQL Server in no uncertain terms what it is you are sending it in the SQL Statement using the CONVERT function with a suitable/matching Style parameter.

Date Conversion flow:

1: User Input to Application code Unless a date control producing a date type value (i.e. not a string value) or a known and/or explicitly specified (non-regional) date string format, make sure you receive the individual date parts separately. Then use:


dtMyDateVar = DateSerial(iYear, iMonth, iDay) + TimeSerial(iHr, iMin, iSec)

to produce the typed variable in your app.

2: Application Code to SQL statement


sSQL = sSQL & " WHERE MyDate = CONVERT(DateTime, '" 
& Year(dtX) & "-" & Month(dtX) & "-" & Day(dtX) & " "
& Hour(dtX) & ":" & Minute(dtX) & ":" & Second(dtX)
& "', 120)"

Of course, I usually have a custom function to convert the date to the desired format. The above example is slightly cheating, since it uses implicit conversion of the integer values returned by the Year() etc. functions. Anyway, I have found that the SQL Server Style 120 (or 121 if you need milliseconds) is easy to read, and difficult to misinterpret.

3: From the database to your application, the resultset would return a properly typed variable - just be on the lookout for potential Null values...

4: From the application to the user, you would usually use a format consistent with your input format. Of course there are tricks that you can employ in order to determine the regional format on the client PC, and massage input and output accordingly. Hint: Convert a date that can be interpreted in any order (such as 01/02/03), and see what you get. Of course, the day, month and year separator may not be the same... (for example dd/mm-yyyy).

Regards,
Tore

- Tore Bostrup

Articles
Sep 15, 2005 - Building an Image Keyword System
Unlike text-based file formats image files aren't made up of words, which makes searching for an image file by keyword difficult. Instead of being able to simply open the file to see what it contains, we're stuck looking at the text around it and other metadata to determine the image's meaning. In this article, Ziran Sun shows you how to build a simple database-based image keyword system that allows you to associate keywords with images and use these keywords to make finding images easier.
[Read This Article]  [Top]
Apr 7, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 2
In the second part of of his article on using MySQL with ASP.NET, Ziran Sun covers how to add a new MySQL user to the database server, assign the user the appropriate permissions, connect to the database, and build a simple ASP.NET page to perform a query.
[Read This Article]  [Top]
Feb 10, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 1
Back in the days of classic ASP, if you were building a database-driven web site, your choice was either to invest a lot of money to get a copy of Microsoft SQL Server (or some other enterprise-ready database) or invest a lot of time finding a way to deal with the performance and scalability limitations of Microsoft Access. Luckily these days there's another viable alternative: MySQL.
[Read This Article]  [Top]
Jan 27, 2005 - Moving a Database from SQL Server 7.0 to SQL Server 2000
Moving or copying a SQL Server database from one machine to another requires a lot of preparation in order to ensure a smooth transfer. In this article, Dina Fleet Berry examines the different methods and highlights the different issues associated with each of them.
[Read This Article]  [Top]
Jan 6, 2005 - Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer
There are many times when using SQL Server 2000 Query Analyzer to debug SQL statements is a better choice than debugging in Visual Studio .NET. In this article, Dina Fleet Berry explains why and walks you through the debugging process step-by step.
[Read This Article]  [Top]
Nov 24, 2004 - Persisting .NET Objects to SQL Server Using SQLXML and Serialization
As a follow up to his article on retrieving objects from SQL Server using SQLXML and serialization, Gianluca Nuzzo discusses saving objects back to SQL Server using a schema definition file and updategrams.
[Read This Article]  [Top]
Sep 14, 2004 - Transaction Processing in ADO.NET 2.0
One area that stands out when comparing ADO.NET 1.x to ADO.NET 2.0 is transaction processing. Bill Ryan shows just how easy transaction processing has become with the TransactionScope object in ADO.NET 2.0.
[Read This Article]  [Top]
Sep 8, 2004 - Custom Object Data Binding with .NET
Developers often use brute force coding to marshal data between the GUI and application objects. In this article, Luther Stanton explains how to use .NET's out-of-the box data-binding functionality to make this job much easier.
[Read This Article]  [Top]
Sep 2, 2004 - Queue MSMQ Messages from SQL Server
Learn how to create a console application to queue a message in Microsoft Message Queuing (MSMQ) and then use an extended stored procedure to call the console application from a SQL Server trigger.
[Read This Article]  [Top]
Aug 30, 2004 - Tuning Up ADO.NET Connection Pooling in ASP.NET Applications
Connection pooling increases the performance of Web applications by reusing active database connections instead of creating a new connection with every request. This article shows how to monitor the connection pool, diagnose a potential problem, and apply the appropriate fix.
[Read This Article]  [Top]

Books
Working with Active Server Pages
Michael Corning, Steve Elfanbaum, David Melnick
Teach yourself Active Web Database Programming ...
Dina Fleet, Matt Warren, Joyce Chen, Alexander Stojanovic

Code Samples
Creating a Unique Cookie with SQL Server
Using File DSNs
Connecting Database on the Fly
Number of Recordset(s) returned by a query or stored procedure
Making Your SQL Universal

Knowledge Base Articles
INFO: ODBC Connection Pooling and ADO
Q166886 - 1997.06.23
FIX: Repetitive Connect/Disconnect May Shut Dow...
Q164734 - 1997.06.23
INF: SQL Logs 17832 With Multiple TCP\IP Connec...
Q154628 - 1997.06.23
INF: How to Access SQL Server Within Active Ser...
Q169377 - 1997.06.23
INF: Frequently Asked Questions About ODBC Conn...
Q169470 - 1997.07.10
HOWTO: Redistributing ADO 1.0 or ADO/R 1.0 with...
Q168122 - 1997.08.09
HOWTO: Calling SQL Server Stored Procedures fro...
Q164485 - 1997.08.21
HOWTO: Determining How to Define a Stored Proce...
Q165156 - 1997.08.21
PRB: Accessing SQL Database Fails on Second Att...
Q166659 - 1997.09.06
INFO: Underlying OLE and OLEDB Provider Errors ...
Q168354 - 1997.09.23


Support the Active Server Industry



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers