TIME datatype in SQL Server 2008 will not accept time from Access form - sql

I am using an Access form on the front end, bound to a SQL Server 2008 table. I have an Arrival Time column of datatype Time.
But I get an ODBC error every time I try to save a record. Error states:
Invalid character value for cast specification.
Time displays as 10:00:00 AM. I have tried with and without a time format in the properties of the field, and with/without an input mask of various types. Does anyone know how to avoid this error?

When I linked a 'Time' Field from SQL Server 2012 Express to an access front end (2010 accdb) using the old 'SQL Server' ODBC driver, it converted it to a Text field, and would not allow an updates. You might consider using a datetime field, or trying a newer ODBC driver. I believe the 'Time' field was first introduced in SQL 2008, so I'm guessing older ODBC drivers don't know how to handle it.

Related

Comparing dates from SQL Server linked table in Access

I have a SQL Server linked table in Access and I am trying to query to extract from a certain date or data ranges (i.e. < 01/31/2017, for example). I tried in the criteria in Access design mode, the following: < #01/31/2017# but it is not comparing correctly.
The field in the SQL server table is datetime data type, I formatted it in Access as Short Date in the properties in design mode.
SELECT dbo_LicensesLiveViewWithRevenue.BAN,
dbo_LicensesLiveViewWithRevenue.PTN,
dbo_LicensesLiveViewWithRevenue.SOC,
dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn,
Format([DeactivationDate],"Short Date") AS DeactOn,
dbo_LicensesLiveViewWithRevenue.RetailPrice,
dbo_LicensesLiveViewWithRevenue.WholeSalePrice,
dbo_LicensesLiveViewWithRevenue.AccountID
FROM dbo_LicensesLiveViewWithRevenue
WHERE (((dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn)< #2017/01/31#)) ORDER BY dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn;
I also tried the query with passing the dates as parameters from a form, with no luck.
SELECT dbo_LicensesLiveViewWithRevenue.BAN,
dbo_LicensesLiveViewWithRevenue.PTN,
dbo_LicensesLiveViewWithRevenue.SOC,
dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn,
Format([DeactivationDate],"Short Date") AS DeactOn,
dbo_LicensesLiveViewWithRevenue.RetailPrice,
dbo_LicensesLiveViewWithRevenue.WholeSalePrice,
dbo_LicensesLiveViewWithRevenue.AccountID
FROM dbo_LicensesLiveViewWithRevenue
WHERE (((dbo_LicensesLiveViewWithRevenue.LicenseCreatedOn)<[Forms]![MainForm]![EndDate]));
The results:
When I run the query directly in SQL server is giving me the correct records with correct dates (in SQL the dates are < '20170131'). In Access I have the same count of records but the dates are showing wrong as in the result pictures.
I would suggest that you open the linked table in design view. Ignore the prompt msg about this action being read only).
If the columns in question are newer date time formats (datetime2), and you link using the standard SQL driver, then such date are seen as TEXT columns, and NOT date/time.
A quick look at the linked table in design view will revel if the columns are seen by access as date or text columns.
If you are using any newer format dates from SQL server, you MUST use the newer native 11 (or later) drivers when you link tables to SQL server. It is for this reason that I tend to stick with the older “default” legacy SQL driver. The legacy drivers are installed and included with windows - and thus no install of drivers is required when you run Access on each workstation.
However, if you are using newer date formats in SQL server, then you need to link the tables using the native 11 drivers, and you ALSO have to distribute and install the native 11 drivers on each workstation in addition to Access (or the Access runtime). So while one should prefer and use the newer SQL drivers, the downside is these drivers have to be installed on each workstation.
So double check the data type for those columns that Access shows in table design mode – if they are text, then you need to re-link with the native 11 drivers.

MSSQL DateTime default is GetDate() doesn't work

I have a Table which was declared to receive GetDate() by default,
the thing i get invalid character value for cast specification.
On most of our servers we didn't got this error, but on one server we got this error.
I solved this issue by creating a trigger that calls a function that updates the inserted record with GetDate().
I would like to hear your opinion what could possibly go wrong.
MSSQL 2008 x64 r2. windows server 2008 R2 datacenter.
If you are getting a cast error then the datatype of the column is not DateTime. You would have to use an explicit CAST instead, or change the datatype of the column.

Why doesn't SQL Server have a pure date and pure time data type?

I have a few SQL Server tables with a datetime field that really only has to contain dates... and the fact that it's a datetime object violates data integrity, because it's possible for data to be inserted with a time - which isn't really valid for this field. The result is that we have to convert it and strip off the time every single time we use it. We've considered adding triggers to make sure that no data can even get in with a time attached... but it seems to me that this should really be part of the database software, and shouldn't need to be specifically programmed each time.
Why doesn't SQL Server have separate date and time data types? Is this going to change in the near future? Do other database platforms have this functionality?
SQL Server 2008 has DATE and TIME data types.
What version are you using?
SQL Server has a pure date and time data type since version 2008, they also added a bunch of new datetime types, now it also goes all the way back to year 1 instead of 1753

Saving a Date/Time Stamp from VB 2005 to MS Access

I am coding ib Visual Basic. I need to store the current system time in MS Access timestamp field. How do I go about it.
Dim row As DataRow = ds.Tables("StudentTable").NewRow
row("SSMA_TimeStamp") = System.DateTime.Now.ToString()
The field name starting with SSMA makes me think that his is a SQL Server table and that its been upsized from Access using the SQL Server Migration Assistant for Access If so Access isn't involved here at all.
If this is indeed the case then it's almost certainly a SQL Server TimeStamp aka RowVersion column which is not updatable by users or code. It is a special field that changes only when data in the row changes. This makes a lot less work for Access (and other programs if they use it) to see if the row has been changed elsewhere when Access goes to update the data. Read up on it in Books Online.

UNDEFINED data type when reading SQL database from Lotus Notes using ODBC: nvarchar

This is the second time it happens to me and before modifying a 3rd party Database structure I wanted to know if anyone knew a better solution:
I'm accessing a MS SQL Server 2008 from a Lotus Notes Agent (Notes 7) to retrieve some data. I use LSXODBC and my "Select" statement works perfect... Except that my agent cannot "understand" Nvarchar SQL Field types. Any other data types work ok (can get the values from number and dates fields without a problem).
It took me a while to figure it out, and I couldn't find a solution (other than modifying the field types on the SQL table to Varchar instead of nVarchar)
I could replicate this both in MS SQL 2005 and 2008.
Last "elegant" solution was to create an SQL view -instead of modifying table structure- with the varchar types instead of nvarchar. Works ok but I have to create a view for each table I'm retrieving data from.
I tried to set the Field type using FieldExpectedDataType Method but didn't work. Still got a DB_TYPE_UNDEFINED.
I thought there might be some configuration issues? or maybe I'm using an old LN Version / ODBC Driver version?
Any hint would be greatly appreciated.
Thank you in advance.
Diego
An old ODBC driver may not support unicode. It was not added until SQL Server 2000 (I'm fairly sure)