Correct Syntax in AEP Query Service | Community
Skip to main content
RyanMoravick
September 5, 2024
Solved

Correct Syntax in AEP Query Service

  • September 5, 2024
  • 1 reply
  • 3014 views

Hey there, 

 

Im trying to run a query in Query Service and trying to understand the correct syntax for looking at certain dates. I want to look at WHERE transactionDate = '2024-09-04'. However, it returns no results. When I run WHERE transactionDate BETWEEN '2024-09-04' AND '2024-09-05', I can see results for 2024-09-04. So my question is when looking at a single date, what is the correct syntax to use?

 

Thanks!

Best answer by ccg1706

Hi @ryanmoravick ,

 

The issue might arise if the transactionDate may  include date and time. 

 

To manage this you can try with the following options:

 

-Using DATE(): WHERE DATE(transactionDate)='2024-09-04'

-Using a range of time to cover the entire day: WHERE transactionDate >= '2024-09-04' AND transactionDate <  '2024-09-05'

 

If using the Date function doesn't give you the expected result you can try with CAST or TRUNC.

-CAST: WHERE CAST(transactionDate AS DATE) = '2024-09-04'

-TRUNC: WHERE TRUNC(transactionDate) = '2024-09-04'

 

¡Hope this helps!

 

Regards, 

Celia

1 reply

ccg1706
Community Advisor
ccg1706Community AdvisorAccepted solution
Community Advisor
September 5, 2024

Hi @ryanmoravick ,

 

The issue might arise if the transactionDate may  include date and time. 

 

To manage this you can try with the following options:

 

-Using DATE(): WHERE DATE(transactionDate)='2024-09-04'

-Using a range of time to cover the entire day: WHERE transactionDate >= '2024-09-04' AND transactionDate <  '2024-09-05'

 

If using the Date function doesn't give you the expected result you can try with CAST or TRUNC.

-CAST: WHERE CAST(transactionDate AS DATE) = '2024-09-04'

-TRUNC: WHERE TRUNC(transactionDate) = '2024-09-04'

 

¡Hope this helps!

 

Regards, 

Celia

RyanMoravick
September 5, 2024

Hi @ccg1706 I used your first solution and it worked. Thank you!

ccg1706
Community Advisor
Community Advisor
September 6, 2024

Hi @ryanmoravick,

 

Great, as always happy to help.

 

Regards, 

Celia