Concat with functions and quation - Data Factory

Bakar, Cem 281 Reputation points
2022-01-24T18:43:45.15+00:00

I am trying to make this work but so far no luck.

WITH myTable AS ( SELECT * FROM myapp.analytics_124168.events_20220123 ) SELECT TO_JSON_STRING(t) FROM myTable as t

Instead of having 20220123, I need to generate the date so it will look like this I think;

@markus.bohland@hotmail.de (WITH myTable AS ( SELECT * FROM myapp.analytics_124168.events_@date ) SELECT TO_JSON_STRING(t) FROM myTable as t

These ` around the table name making it difficult.

Any ideas?

Thank you.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
{count} votes

1 answer

Sort by: Most helpful
  1. svijay-MSFT 5,256 Reputation points Microsoft Employee Moderator
    2022-01-25T13:47:06.597+00:00

    Hello @Bakar, Cem ,

    Thanks for the question and using MS Q&A platform.

    You could use the expression formatDateTime(utcnow(),'yyyyMMdd') .

    It gives the date in the below format :

    168266-image.png

    You can use the above expression in the concat function.

    @concat('WITH myTable AS ( SELECT * FROM myapp.analytics_124168.events_',formatDateTime(utcnow(),'yyyyMMdd'),')SELECT TO_JSON_STRING(t) FROM myTable as t')  
    

    168229-image.png

    From your comment I understand - I understand that you'd want a days old data. If that's your requirement - you could use the below expression.

    @formatDateTime(adddays(utcnow(),-1),'yyyyMMdd')  
    

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.