Thursday, March 8, 2012

A simple Update query using a date - conversion from msaccess

I'm converting an ASP system from using msaccess to SQL Server as the db engine, and I'm stumped on the following query

update
timecard
set
TcdDate = #3/18/05#

TcdDate is defined as a date/time type

It will not run with the date bracketed by # signs, and when I take them out, 1/1/1900 is stored in the dbs. Is there a different symbol to bracket the date with or should I be using a function to convert the date?Converting a whole database into SQL Svr?? Why dont u try ur hand at writing a DTS package and running it. It does everything for u automatically though u need to spend some time writing it. It is absolutely reusable.|||Your sql stmt should be :

UPDATE
timecard
SET
TcdDate= '3/18/05'

In sql server the datetime datatype is treated as string hence you need to wrap it in quotes.|||Argh! I thought I had tried that already. But, in retrospect, I had coded TcdDate = 3/18/05, and thus my problem lay with a couple of single quotes.

Sometimes it takes a fresh set of eyes to look at a problem.

Thank you for your help.|||FWIW it would be safer to stick to ISO date format (YYYYMMDD). This will insure that the month and date portions are recognized correctly regardless of the language settings on the SQL Server:


UPDATE
timecard
SET
TcdDate = '20050318'

Terri

No comments:

Post a Comment