SQL query not working - Mismatch using Where condition - sql

I'm trying to connect one database to excel.
When the table its linked without any conditions with works perfectly.
When I'm trying to put a WHERE condition I got the type mismatch error.
Where Data.`InfoCreation Date`>= ?
On access the field is using date/time for Data type and it looks like:
InfoCreation Date
18/12/2018 05:49:00
And I am trying to match in excel with a date format type like: 18/12/2018
What I want to have is to select all the dates before one choosed day.
Can someone help me with this?
Thanks

You would need to convert your string to a date. For that you can use the msaccess FORMAT() function
Data.`InfoCreation Date`>= Format(?, "dd/mm/yyyy")

Related

I try to convert date format in sql but it still doesn't work

I use the CONVERT() function to trying convert the date format like DD/MM/YYYY with code 103 when I query database, and nothing happens. The data field still displays default format with YYYY/MM/DD.
UPDATE STAFF
SET BIRTH = CONVERT(smalldatetime,'26/08/1900',103)
WHERE ID = 'SF01'
How can I fix this problem ? I'm a newbie so i don't know lots of SQL
Avoid formatting dates in your database, it should be done in the application that queries the data. But IF you still need to do it in your database for whatever reason:
If you want to store the date in the DD/MM/YYYY format in your table then you can do 2 things,
Change your column data type to varchar(not ideal and you should try avoiding this method)
Change the regional settings on the machine running SqlServer and keep it as a date type (this is somewhat useless if you plan on querying data from another app as the app will probably format the date to its local format).
In case you decide to store it as varchar you will need to use the Format function when inserting or updating like this: Format(MyDate, 'DD/MM/YYYY').

BigQuery timestamp field in Data Studio error

I have data in a BigQuery instance with a some date fields in epoch/timestamp format. I'm trying to convert to a YYYYMMDD format or similar in order to create a report in Data Studio. I have tried the following solutions so far:
Change the format in the Edit Connection menu when creating the Data Source in Data Studio to Date format. Not working. I get Configuration errors when I add the field to the Data Studio report.
Create a new field using the TODATE() function. I always get an invalid formula error (even when I follow the documentation for this function). I have tried to change the field type prior to use the TODATE() function. Not working in any case.
Am I doing something wrong? Why do I always get errors?
Thanks!
The function for TODATE() is actually CURRENT_DATE(). Change timestamp to DATE using EXTRACT(DATE from variableName)
make sure not use Legacy SQL !
The issue stayed, but changing the name of the variable from actual_delivery_date to ADelDate made it work. So I presume there's a bug and short(er) names may help to avoid it
As commented by Elliott Brossard, the solution would be instead of using Data Studio for the conversion,use PARSE_DATE or PARSE_TIMESTAMP in BigQuery and convert it there instead.

Assign an oracle date to an SSIS variable

I am trying select a date from an Oracle DB (1 row result) and assign its value to an SSIS variable. I tried to convert it to_char (which would also work great to me) but I still get an error "SSIS value does not fall within the expected range"
You'll need to ensure your SSIS variable is of type String.
I expect you'll still need to convert the Oracle date to a string data type with the to_char method but I would have to test and don't have an Oracle instance I can test against.
Apparently the problem was about the name of the Result Name from whatever I was using to '1'. The helpful post that solve my problem is: https://dba.stackexchange.com/questions/129106/ssis-odbc-mapping-result-set-columns-to-variables-returns-error-value-does-not

How do you convert SQL mm/dd/yy to mm/dd only?

How do you convert SQL mm/dd/yy datetime to mm/dd only? On Microsoft server.
Thanks all.
With dates and times it is an extremely common mistake to believe that what you see is what is stored. If the field is date, datetime, smalldatetime or datetime2 then what is stored are integers, not strings. So if the field is one of these, then:
convert(varchar(5),[date_field],1)
or
format([date_field],'MM/dd') -- mssql 2012 onward
If the information is a string already then left() will do the job.
Since you have specified an input format, the input must already be a string. Simply truncate with
cast(dateIn as char(5)).
You can use LEFT to just return the day and month:
SELECT LEFT('12/12/2000', 5)
I realize this isn't directly answering your question the way you asked it, but the best advice I can give is: Don't.
Instead, send back the field in its native datetime type. The database is not the place to be doing formatting. Instead, format the date in your application code.
For example, if you are calling SQL Server from a C#/.NET application, you could retrieve the value from a DataReader like this:
DateTime dt = (DateTime) reader["YourDateTime"];
Then you would format it as a string like this:
string s = dt.ToString("MM/dd");
This will ensure that the date is formatted correctly. If you are using a different language to call SQL Server, there are probably similar methods in that language.
One of the problems with the other approach mentioned (trunacating the string) is that the original value might not be formatted in mm/dd/yyyy to begin with. That all depends on the environment settings where the SQL Server is running. If you run the same code on an environment with dd/mm/yyyy settings, you would have unexpected results. This is avoided by using the native data type, the way I described.

SQL Syntax question

I'm trying to remember the syntax to change a date field into a string. I know I'm close but not 100% correct. Here is what I'm using so far: TO_CHAR(FIELD_NAME). I'm using an Access database. The error I'm getting is: undefined expression. Any help would be very much appreciated.
Use either CStr(dateField) or Format(dateField) to convert.
Additionally you can add parameters to Format() to show it in a different format, such as:
Format(dateField, "general date") 9/12/2010
Format(dateField, "long date") Monday, September 12, 2011
Given that you're using MS Access and its a date field you're probably not just looking to convert to string but to also format the Date. If that is indeed the case you'll want the Format function
SELECT Format ([DateCreate], "yyyy/mm/dd") AS Foo
FROM MSysObjects;
If you're using SQL Server, try out CAST or CONVERT
You can use the CONVERT function, like this:
CONVERT(VARCHAR, DateField, 100)
Here's a link that shows the different date formats you can use:
http://www.sql-server-helper.com/tips/date-formats.aspx
I assume SQL Server as you're questions in the past are .NET Questions.
Use CONVERT
http://msdn.microsoft.com/en-us/library/ms187928.aspx