I'm running the following query on a table from SQLPro for MSSQL:
SELECT * FROM MyTable where Date = '2016-06-28'
The Date column contains fields formatted as datetimes for example: '2016-06-27 19:00:00:000'. When I run the query it returns results whose entries in the Date column are one day earlier than the date I queried for. So in the above example all results returned have date '2016-06-27'. There is data for the date I'm looking for since if I query for '2016-06-29' I get the data for the 28th.
Further, when I query from a cursor using pymssql I get the data for the right dates so it seems like the issue is with SQLPro and not the database itself. Anyone know what's going on/how to fix it?
Developer here. It is indeed a bug with SQLPro. I've sent a fix to #stableMatch which should resolve the issue.
Related
My database is SQL Server, and the thing is that "dates" are stored as a string type. If I execute that query it does not order properly.
What I want to do is, get each day's value for between 7am and 8 am. For example, I want to get 14th of June records for between 7am an
Use CAST() or CONVERT() in your WHERE / ORDER BY clause conditions.
However, you should store dates as date types instead of strings to avoid such problems.
As part of my job duties, I'm responsible for extracting data from our vendor's Oracle 11g database, and loading it into our SQL Server 2016 database. I've been doing this successfully with SSIS and the Attunity Oracle connectors.
Today I was informed that there was a new column added to the existing Invoices table on the Oracle side. There was already a DATE column called Order Date, which contains valid date values with zero'd times, like 2017-12-25 00:00:00.
The new column is called Order Date Time and is also a DATE column. When I opened up the SSIS package and pulled up the Oracle source in my DFT, I previewed the data and found the values in Order Date Time to be 2432-82-75 50:08:01. I tried converting the column with CAST and all the TO_* functions, but the conversions either failed outright, or returned a string of zeros.
TO_CHAR("Order Date Time", 'YYYYMMDDHH24MISS')
yields 00000000000000
After a bit of Googling for "Oracle date value invalid", I'm now thinking that these DATE values are actually corrupted. Am I missing anything here? Is there some sort of special Oracle-specific technique for storing time values in a DATE column that I may not be aware of?
(And yes, it does bother me quite a bit that our vendor added another DATE column instead of just using the time portion of the existing Order Date column.)
Unfortunately, Oracle database engine allows inserting invalid date values, which leads to many problems especially when importing data to others database engines such as SQL Server.
To handle this issue, you have to implement the logic that fits your needs, as example:
You can exclude these records from you queries by filtering on acceptable date ranges: (WHERE date between ...)
You can Update records with invalid values by replacing with NULL
You can use a CASE statement in your query to replace values with NULL
I faced this issue one time while importing data to SQL Server from an Oracle data source, there was unacceptable date values, i decided to update all records where date are invalid and replace with NULL values before starting the import process.
There are many links related to this issue:
Detecting invalid values in the DB
How to identify invalid (corrupted) values stored in Oracle DATE columns
Corrupt date fields causing query failure in Oracle
Invalid Date in DATE Column SQLPlus VS SQLDeveloper
Ask Tom - date validation in oracle
Dealing with invalid dates
Error: Invalid date format
DB Connect; Oracle DB date field data is corrupt
I am converting a Google Sheet to a SQL database table. When it loads the Excel sheet (I copy the Google Sheet data to Excel and import it) SQL changes some of the data types. I have a column in my Excel sheet that is a date that SQL converts to nvarchar. When I try to convert it back to a date data type, I get this error:
"Conversion failed when converting date and/or time from character
string."
My code seems to be correct...I'll show you.
USE Sample
ALTER TABLE ['RM Item List$']
ALTER COLUMN [Kosher Cert] date
Can someone give me an idea why this doesn't work? I know questions about data conversion have been asked ad nausea, but I didn't see an answer that helped me solve my problem. SQL converted my dates in the Kosher Cert column to strings of five numbers. Any help would be appreciated.
This related topic might be helpful:
T-SQL to convert Excel Date Serial Number to Regular Date
It would probably make most sense to add a column to your table with the date type, populate it and then drop the nvarchar column:
ALTER TABLE ['RM Item List$'] ADD [KosherCert] date;
UPDATE ['RM Item List$']
SET [KosherCert] = DateAdd(Day, Convert(int, [Kosher Cert]), '1899-12-30');
I am exporting data from Excel to SQL Server through an API. Everything is supposed to save as nvarchar but date is stored as int value (automatically). How can I keep, in SQL table, date value as it is i.e. like 01/01/1990 instead of 32874.
Might be a basic question, Googled and looked into SO but couldn't find what I am after yet. Help appreciated!
In SQL Server, you can convert to a date by using:
select dateadd(day, 32874, '1899-12-31')
There is probably also a way to fix this when importing the data, by treating it as an actual date or string.
I’m having a problem with a linked Informix table in MS SQL Server 2008r2. When I query this table, it seems to ignore some of the criteria I’m passing to it but not others. For example if I put a condition on the rowdate field the remote query part of the execution plan does not show any WHERE clause but if I put criteria on another field such as ACD it does show.
It seems it does not pass any criteria on the rowdate field but does on all others.
I know the field is indexed on the Informix side. If it helps the table I’m linking is from Avaya CMS and it is linked via the OpenLink ODBC driver.
EDIT:
As far as I know it is Informix Dynamic Server 2000 and it is on Solaris. The column comes up as a DATE data type which is correct. I have tried passing the criteria as ‘2010-08-03 00:00:00’, ‘2010-08-03’, CONVERT(date,’2010-08-03’) and a few more variations. When the data is returned to SQL server it is in the format yyyy-mm-dd.
When I view the execution plan I can see the remote query with all the other criteria followed by a filter for only the rowdate field.
I know that rowdate is indexed and that the driver does normally communicate that information as we use it in other applications (Business objects and MS Access) and they don’t have a problem
I managed to figure it out but it is the strangest thing ever. I went down the route of passing the date in different formats. My default is to use the normal YYYY-MM-DD that of course did not work so I tried YYYY-MMM-DD, still nothing. After going through LOTS of combinations I found one that works Mmm-DD-YY and it has to be exactly that! SEP-21-2010 wont work but Sep-21-2010.
I wonder if this is just a strange hang up from Informix or something in the driver, anyway it works.
On a side note has anyone noticed how strange it is that people from the America write the date month, day year? Stop and think about it for a second, do you say the number 2410 as “Four hundred, ten, two thousand”? The best part about it is try asking yourself this, what day is American independence day? Most Americans say “That’s easy you limey person it is the 4th of July” hmmmm day month (year), the only date they say round the right way is the date they got their independence. I will leave it up to the SO community to see the irony in that
Example query below:
select *
from OPENQUERY (AVAYA, 'select row_date,starttime,intrvl,acd from root.hagent where
row_date = ''NOV-22-2012'' and acd = 1 and split = 1 and starttime = 1900')
By the way I managed to extract accurate data via both MMM-DD-YYYY and Mmm-DD-YYYY.