Delphi 6, ADO, MS database "Date" field is same as ftWideString - sql-server

I want to copy elements to a remote MS-SQL database.
I got conversion error on it.
When I checked the ADOTable structure I saw the MS field
WHENCREATED DATE [NULL]
is converted to
ftWideString 10
Hmmmmm....
Is it normal? Or I can set something to Date fields are come as TDateTime?
The Provider is "SQLOLEDB.1"

Its a DATE (yyyy-mm-dd) type which was introduced in SQL Server 2008 as an alternative to the DATETIME type.
Because SQLOLEDB.1 precedes this there is a backward conversion to DBTYPE_WSTR, using an updated provider (SQLNCLI) would be preferable.

Related

Date format changed on imported SQL Server DB

I have migrated a SQL Server database from one server to another. I did this via export to BAK and then Restore on the new machine.
Seems to be a different format somewhere, as a simple query that was working previously, is now throwing an error, but I cannot see what it might be (collation and 'containment' info seem the same).
The old SQL Server version: Microsoft SQL Server 2012 - 11.0.6598.0 Express Edition
The new SQL Server version: Microsoft SQL Server 2019 - 15.0.2080.9 Express Edition
The error, below, refers to a date format:
SELECT userID FROM tblLogin
WHERE CAST('30/09/2021 00:52:14' AS datetime) < DATEADD(n,600,accessDate)
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
(Column accessDate is of type datetime, null)
Always always ALWAYS use the ISO-8601 date formats for literals in Sql Server. For historical reasons, the preferred option for date-only values is different than date-time values, so you want either yyyy-MM-ddTHH:mm:ss for date and time or yyyyMMdd for date-only. But the really important thing is always go in order from most significant (year) to least significant (second).
Anything else isn't really a date literal at all: it's a string you must convert to a date.
If we follow this correct convention (because anything else really is incorrect), you get it down to this (which doesn't even need the CAST() anymore, because Sql Server can interpret it as datetime from the beginning):
SELECT userID
FROM tblLogin
WHERE accessDate > DATEADD(n, -600, '2021-09-30T00:52:14')
Also note I inverted the check, moving the DATEADD() function to act on the literal, instead of the column. This is always preferred, because it can work with any index you may have on the accessDate column. The original code would have rendered any such index worthless for this query.

oracle timestamp 6 convert to sql server datetime2 error

I am using SSIS to convert some oracle data to sql server. I found for Oracle date timestamp6 like this
26-DEC-82 12.00.00.000000000 AM
will cause the conversion in SSIS to fail
Error: Year, Month, and Day parameters describe an un-representable
I think it's because ssis don't know whether it's 2082 or 1982, so don't know how to convert.How can I convert the oracle dates to something with yyyy for the year part?
update: tried to_char function mentioned by Hadi. I can see the year now is 2682 (most of them). I added a pic showing with to_char and original column for plate_date and sold_date columns. As you can see most of the years are 26xx, two exceptions are 18xx. Can someone explain?
In the Oracle Source use an SQL Command to convert TimeStamp to nvarchar using TO_CHAR() function and use the universal data format yyyy-MM-dd HH:mm:ss:
TO_CHAR(SOURCECOLUMN, 'YYYY-MM-DD HH24:MI:SS')
And in SSIS data flow add a derived column with the following expression:
(DT_DATE)[SOURCECOLUMN]
Or add a data conversion transformation and convert the column to date data type.
In SQL Server, the datatype "timestamp" is nothing to do with dates or times.
Microsoft have renamed their old "timestamp" datatype to "rowversion" because it is just an 8-byte number that is used to record a sequence of “row changed” events.
On the other hand Oracle's "timestamp" really is about time because Oracle's "timestamp" extends their "date" datatype. more here.
Unfortunately, SQL Server still recognises "timestamp" as a valid datatype name.
So, I suspect that your error message may have something to do with the timestamp-timestamp homonym.

Access Show Date In MMDDYYY Format

I have a backend SQL Server 2008 R2 table linked into an Access 2013 database. The field name is entereddate and it is is a date field type in SQL Server. When I view the data from within SSMS it appears as a date and I just Cast it to the proper format. However, on my access form I can not get the date to format to mmddyyyy. I tried adding an input mask on the form field (called txtentereddate) but that is not altering the way the date is displayed.
What must I change to have the date in access dispaly as MMDDYYYY?
You could try the MS Access format() function:
format(date, "mmddyyyy")

Access DB type mismatch with SQL server

I have migrated an Access database to SQL server. Many of my "dates" were stored in the Access database in the format "DD/MM/YYYY". However, I notice the SSMA has updated all date columns to the format "DD-MM-YYYY HH:MM:SS". What type should we choose in SQL Server to accomplish the same? The thing that is I want to keep it this way as else we need to change the underlying code.
Much appreciated for your help!
According to this http://social.msdn.microsoft.com/Forums/en-US/4920b4f5-6855-4855-96a9-43f9365d63a0/change-sql-server-date-format the format SQL Server stores datetime fields is generic. You can convert the datetime fields and convert it to varchar in order to show the formal you want.
For example this
convert(varchar, datimefield, 103)
will convert the datetime field using the format 'dd/mm/yyyy'
You should be able to use the date datatype to not store the time, as according to This Link, but only in 2008 or 2012
I checked if it works as such on my SQL Server 2008, and it does.
This will still show it with a dash rather then a slash and in the order YYYY-MM-DD though.

Values In Timestamp Field Displayed In Hex (0x000000000000000866) On Microsoft SQL Server 2008

I have a table where I save emails that have been sent. I decided then to add a TimeStamp field to this table so I can track when the e-mail had been sent. Data is being written to the table with out any issues, but when I go to view the table contents using Microsoft SQL Server 2008 Management Studio, the data contained within the Timestamp field is displayed like this: 0x000000000000000000845, even in records that have been written to the database since the Timestamp value was introduced
I then changed the field type to datetime, and it then displays a date. But it displays the date 1900-01-01 00:00:23 for example. I then changed it back to the Timestamp field, and it returned back in to it's current Hexadecimal format.
Am I doing anything wrong?
Cheers
I decided then to add a TimeStamp
field to this table so I can track
when the e-mail had been sent
Ah yes. Reading teh database would have shown you that the TMIestamp field - which is a legacy from Sybase server -does NOT store a timestamp. Basically it is something like a global operations counter. It has NO relation to time.
If you want a real timestamp, put in a DateTime type of column and set the system time as default / through atrigger etc. Timestamp is totally unsuiteable for that.
Again, no a MS thing - MS SQL Server started as Sybase SQL Server port for windows, and the Timestampdata type is a Sybase legacy.

Resources