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 select "yes" above
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.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 295 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 97 SQL DataFlows
- 608 Datasets
- 2.1K Magic ETL
- 3.8K Visualize
- 2.4K Charting
- 710 Beast Mode
- 50 App Studio
- 39 Variables
- 668 Automate
- 170 Apps
- 446 APIs & Domo Developer
- 45 Workflows
- 7 DomoAI
- 33 Predict
- 13 Jupyter Workspaces
- 20 R & Python Tiles
- 391 Distribute
- 111 Domo Everywhere
- 274 Scheduled Reports
- 6 Software Integrations
- 116 Manage
- 113 Governance & Security
- Domo Community Gallery
- 31 Product Releases
- 9 Domo University
- 5.3K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 103 Community Announcements
- 4.8K Archive