Question on Domo SQL syntax
Hello all,
I am trying to do Magic Transform using SQL option. I have embedded a SQL query but it is erring as it is not compatible with Domo syntax. Appreciate your help in this regard.
DATE_PART('WEEK',CAST(TO_CHAR(TO_DATE(TO_CHAR(PRODUCT_KEY),'YYYYMMDD'),'YYYY-MM-DD') AS DATE)) AS "SaleWeek",
DATE_PART('YEAR',DATE(ProductSale_Timestamp))
I am getting syntax error while running my SQL query in Domo. I believe it is because of the above conditions as Domo is not compatible with DATE_PART. Can someone let me know an equivalent condition I can use in Domo SQL?
Thank you!
Best Answers
-
Are you using a Magic ETL transformation with a formula tile or a MySQL transformation?
Is your PRODUCT_KEY field a date field or a text field or a numerical field?
Why are you casting it to a string, then to a date, then to a string and finally back to a date again?
Assuming you're using a formula tile in Magic ETL:
If PRODUCT_KEY is a date then you can simplify it with:
WEEK(`PRODUCT_KEY`)
If it's a string:
WEEK(STR_TO_DATE(`PRODUCT_KEY`, '%Y%m%d'))
If it's a number:
WEEK(STR_TO_DATE(STRING(`PRODUCT_KEY`), '%Y%m%d'))
Your other formula becomes:
YEAR(`ProductSale_Timestamp`)
Domo utilizes the MySQL format strings for dates and most of the function names / types.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
@Aag2023 For the product key, you can transform this into a date using the STR_TO_DATE() function:
WEEK(STR_TO_DATE(`PRODUCT_KEY`,'%Y%m%d'))
Since `ProductSale_Timestamp` is already in a datetime format, @GrantSmith's formula should already work for that.
1
Answers
-
Are you using a Magic ETL transformation with a formula tile or a MySQL transformation?
Is your PRODUCT_KEY field a date field or a text field or a numerical field?
Why are you casting it to a string, then to a date, then to a string and finally back to a date again?
Assuming you're using a formula tile in Magic ETL:
If PRODUCT_KEY is a date then you can simplify it with:
WEEK(`PRODUCT_KEY`)
If it's a string:
WEEK(STR_TO_DATE(`PRODUCT_KEY`, '%Y%m%d'))
If it's a number:
WEEK(STR_TO_DATE(STRING(`PRODUCT_KEY`), '%Y%m%d'))
Your other formula becomes:
YEAR(`ProductSale_Timestamp`)
Domo utilizes the MySQL format strings for dates and most of the function names / types.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
Thank you @GrantSmith for your response. I am using MySQL transformation. The data type for the produtkey field is Floating decimal in Domo. I tried above formats and it did not work. Thanks for sending the link. I will check the same.
0 -
Sure @MichelleH
In DOMO, This is how it looks like when I look at the data section.
Product Key (Floating decimal type) -
ProductSale_TimeStamp (Time stamp type)-
0 -
Grants solution for the second date is correct:
YEAR
(`ProductSale_Timestamp`)
Is that still not working for you?
For the first part try this:
YEAR(FROM_UNIXTIME(`PRODUCT_KEY`))
If I solved your problem, please "accept" my answer as the solution
1 -
@Aag2023 For the product key, you can transform this into a date using the STR_TO_DATE() function:
WEEK(STR_TO_DATE(`PRODUCT_KEY`,'%Y%m%d'))
Since `ProductSale_Timestamp` is already in a datetime format, @GrantSmith's formula should already work for that.
1 -
Thank you @MichelleH and @GrantSmith! This worked!!!
0
Categories
- All Categories
- 1.1K Product Ideas
- 1.1K Ideas Exchange
- 1.2K Connect
- 966 Connectors
- 254 Workbench
- Cloud Amplifier
- 1 Federated
- 2.4K Transform
- 75 SQL DataFlows
- 499 Datasets
- 1.8K Magic ETL
- 2.7K Visualize
- 2.2K Charting
- 360 Beast Mode
- 19 Variables
- 481 Automate
- 101 Apps
- 376 APIs & Domo Developer
- 6 Workflows
- 22 Predict
- 6 Jupyter Workspaces
- 16 R & Python Tiles
- 316 Distribute
- 64 Domo Everywhere
- 252 Scheduled Reports
- 59 Manage
- 59 Governance & Security
- 1 Product Release Questions
- 5K Community Forums
- 37 Getting Started
- 23 Community Member Introductions
- 63 Community Announcements
- 4.8K Archive