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.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 618 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 741 Beast Mode
- 58 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 395 Distribute
- 113 Domo Everywhere
- 276 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive