Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
alau020
Frequent Visitor

Select records using date range by SQL statement

Hello,

I am trying to get records from a database (ODBC connection) where the documentDate is greater than 1/04/2017. 

 

E.G i have entered this SQL statement...

 

SELECT Amount, quantity, documentDate FROM SalesLineItem
WHERE documentDate > '1/04/2017'

 

Data Type from the databaseData Type from the database

I keep getting errors, for example......  Invalid combination of types compared: DATE and VARCHAR" or Invalid combination of types compared: DATE and BIGINT" if i have the date format as 1/04/2017

 

This is the format of documentDate in power bi

Power BI Data Type.PNG

 

Any thoughts on how to fix this? have I go the wrong format after the WHERE statement?

 

Many thanks

 

1 ACCEPTED SOLUTION

The data type was a timestamp and the solution that worked for me is as follws.

 

SELECT Amount, quantity, documentDate FROM SalesLineItem
WHERE documentDate > {ts '01/04/2017'}

 Thank you for your input.

View solution in original post

5 REPLIES 5
Phil_Seamark
Microsoft Employee
Microsoft Employee

It might be safer to format your date a different way.

 

eg.

 

SELECT Amount, quantity, documentDate FROM SalesLineItem
WHERE documentDate > '2017-04-01'

 

What is the datatype of the documentDate column in the SalesLineItem table in the database?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

The documentDate column datatype is DateTime

 

Data Typoe in Database.PNG

 

Thank you

So did my suggestion work?

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

The data type was a timestamp and the solution that worked for me is as follws.

 

SELECT Amount, quantity, documentDate FROM SalesLineItem
WHERE documentDate > {ts '01/04/2017'}

 Thank you for your input.

No, the suggestion did not work. I still get the same errors!!!!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.