2017-11-17 06:35:41.0000000 - this is a value of a column FileProcessDate in a SQL Server table. I am trying to build an incremental logic and I would like to use this date (directly) in Oracle to build that logic.
I am using the following query in Oracle
SELECT *
FROM EVENT
WHERE TIMESTAMP > TO_DATE('2017-11-17 06:35:41.0000000', 'MM/DD/YYYY HH:MI:SS')
But I am getting an error
not a valid month
You need to use correct timeformat:
SELECT *
FROM EVENT
WHERE TIMESTAMP>TO_TIMESTAMP('2017-11-17 06:35:41.0000000','YYYY-MM-DD HH24:MI:SS.FF')
DBFiddle Demo
Related
I have an ODBC linked table in MS Access to SQL Server. In a query in MS Access, I have the following expression on a field:
DATE() - [DATE] (a field).
I need to change MS Access function DATE(), i.e. current date to SQL Server GETDATE(). How can I cast this in the expression builder in MS Access?
You can't really use the GetDate() t-sql server side value.
However, what you could do, is in place of using linked table to the sql server table?
You could create a view and have this
SELECT *, GETDATE() as MyServerDate FROM tblInvoices.
Now, in your client side query, you have a column called MyServerDate.
And thus you could do this:
SELECT *, (DATE() - [MyServerDate] as MydueDate from MyView
Of course the other way would be to use a pass-though query, but they are read-only. So if the sql is only for a report, or some screen display, then you could consider using a 100% server side query. So, you create the query in Access, but set it as a PT query. As a result, the raw SQL syntax in that Access query you build will have to be t-sql sql, not access sql.
I have severe troubles to set up an MS access application that uses linked tables to an SQL Server 2012 Database.
The problem is that SQL Queries have problems to interpret German dates: e.g. "31.12.2019" doesn't work, "01.01.2019" works. So I suspect that it is a problem with localization. E.g.
select * from table where date >= [Forms]![someForm]![fromDate]
[Forms]![someForm]![fromDate] is a string in a form, edited by a date picker.
I was able to solve the problem by using the ODBC Microsoft SQL Server Setup Wizzard, and selecting "Ländereinstellungen verwenden" (engl. use country specific settings).
(Sorry the following screenshot is in German).
I would like to specify this in a classic ODBC connection string: e.g
DRIVER=ODBC Driver 13 for SQL Server;SERVER=.\SqlExpress2012;Trusted_Connection=Yes;APP=Microsoft Office;DATABASE=suplattform;?country-specific=yes?
However I did not find such an parameter in any documentation. Is this possible?
Best regards
Michael
Also, specify the data type of the parameter - and date is a reserved word in Access SQL:
parameters [Forms]![someForm]![fromDate] DateTime;
select * from table where [date] >= [Forms]![someForm]![fromDate]
I have a table in SQL Server with a date column set to default date, however, when I fetch the data from the server using VBA I get the date column in string format. Is there any way I get the date as in date format?
Can you you advise how you are bringing in the data? EG from inbuilt connectors or via a recordset via VBA objects?
A quick hack which I wouldn't advise without really testing would be this :
Select DateDiff(DD, '1899-12-30', date_column) AS [column] from TABLE_x
What is this doing?
In Excel dates start 01-01-1900. When you change a date to 'General' you find it's actually a number with a format. The above date difference will give you the excel number version of the Date.
EG to get today 29/11/2019 which will be 43798 when cell format is 'General'.
Select DateDiff(DD, '1899-12-30', '2019-11-29') AS [column]
More info here
Non MS site explaining the situation
MS Office Info touching on the subject
Please note this basing your question on a SQL formatted date.
I'm trying to migrate data from a Oracle database to SQL Server. The query has invalid dates so I want to change the invalid dates to NULL when I place them in the SQL Server 2012. I'm using SSIS and I'm trying to create a derived column to handle it for me but I can't get the expression right.
The expression I have is :
[Date_Column] < 1900-01-01? NULL(DT_WSTR,50) : [Date_Column]
This is not the only syntax I tried, I also tried
[Date_Column] < "1900-01-01"? NULL(DT_WSTR,50) : [Date_Column]
[Date_Column] < (DT_DBDATE)1900-01-01? NULL(DT_WSTR,50) :[Date_Column]
And many others.
Is there a better way to do this?
I'm not too familiar with PL/SQL but if you have a way for me to just edit it in the query rather than using a transformation that would be great!
Also, when I'm trying to migrate the data from Oracle to SQL Server using SSIS, it fails and throws out a data format error. All I am doing is putting the data into a staging table in SQL Server (using an OLE DB source connected to OLE DB destination). The data types are just DB_TIMESTAMP but it won't complete. It will only load 1/4th of the data.
Thank you!
On the Oracle side you can turn dates earlier than 1900-01-01 into NULL values with a CASE expression in your query, e.g.
with t as (
select date '1000-01-01' as date_column from dual
union
select date '2000-01-01' as date_column from dual)
select date_column,
case when date_column < date '1900-01-01' then null else date_column end new_column
from t
DATE_COLUMN NEW_COLUMN
----------- ----------
1000-01-01
2000-01-01 2000-01-01
While using the Microsoft SQL Server Report Builder, I am able to execute a query in the Query Designer and retreive the result. The query has a where clause on dates.
select * from table where DB_timestamp > to_date(:StartDate, 'mm/dd/yyyy') and DB_timestamp < to_date(:EndDate, 'mm/dd/yyyy')
On execution, I get a pop up where I enter the two variables (StartDate & EndDate) in the given formats. Now when I try to run the same for generating a report, I have to select the two variables using a calender picker. Altough the dates show up in the desired format, I always get the below error:
An error occured during local report processing.
Query execution failed for dataset 'XYZ'.
ORA-01843: not a valid month
What can cause the query to run successfully in one place but throw an error when the variables are selected by the calender picker?
There mught be some kind of culture clash going on. If SSRS is sending dd/mm/yyyy and your db is expecting mm/dd/yyyy things will not work as expected or even crash on certain dates.
I would remove the to_date function from the where clause, e.g.
where DB_timestamp > :StartDate and ...