How to fetch data from SQL server with dynamic date

Sarah Chen 21 Reputation points
2022-08-04T16:08:24.297+00:00

Hi,

I would like to fetch data from SQL Server with SQL statement for power query as below:

Select * from A where transaction date = ‘2022-08–03’.

It works well however if the date will be dynamic which manually entered everyday.

Normally the date is minus 1 day but if today is Monday then will be minus 3 days.

But still prefer to take the date from cell where I enter it manually.

In this case, how should I write it?

Select * from A where transaction date = ?

Thank you!

SQL Server | Other
{count} votes

Answer accepted by question author
  1. YufeiShao-msft 7,151 Reputation points
    2022-08-05T07:39:28.533+00:00

    Hi @Sarah Chen ,

    You need tell us the tools you used
    It seems that you may need enter the date manually into the T-sql
    https://www.youtube.com/watch?v=OTBBX485Fg8

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

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Jingyang Li 5,901 Reputation points Volunteer Moderator
    2022-08-04T16:17:13.89+00:00
    declare @dt date    
    Select @dt=Dateadd (day,-Case when datename(weekday,getdate())='Monday' then 3 else 1 end ,getdate())  
    --print @dt  
    Select * from A where transactiondate = @dt  
    
    0 comments No comments

  2. Sarah Chen 21 Reputation points
    2022-08-05T04:55:06.807+00:00

    Thanks!

    I am wondering if I can do this way?
    Take the date from parameter where I entered manually?

    228300-5a4edbd6-8000-401f-9cc2-595628479bcc.jpeg


  3. Olaf Helper 47,581 Reputation points
    2022-08-05T05:16:19.45+00:00

    which manually entered everyday.

    Entered where? How is the data quried? Which data provider?

    0 comments No comments

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.