Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi,
I am building a query by connecting to a SQL Server Table. To avoid having all the rows I have done a custom SQL Statement to filter while connceting to SQL server as following.
select [$Table].[CreatedDate] as [CreatedDate],
[$Table].[Site ID] as [Site ID]
from [dbo].[vw_xxxxxxx] as [$Table]
WHERE ([CreatedDate] >= N'2016-08-20 00:00:00') Now whenever I run this query I need to see all the rows WHERE ([CreatedDate] >=(Today) - (2 years).
So if I run it today (08/20/2018), I need to see the rows with Created Date values from 08/20/2016. If I run it tomorrow (08/21/2018), I need to see the rows with Created Date values from 08/21/2016.
Is there any way to dynamically pass on this criteria to SQL statement.
Appreciate any help.
Thanks
Solved! Go to Solution.
Hi @smpa01,
Since this is a direct SQL Statement, you should be able to directly use GETDATE() function as in case of SQL Server.
Did you try something like this
select [$Table].[CreatedDate] as [CreatedDate],
[$Table].[Site ID] as [Site ID]
from [dbo].[vw_xxxxxxx] as [$Table]
WHERE ([CreatedDate] between getdate() and CAST((CAST(YEAR(getdate())-2 as VARCHAR(4))+'-'+CAST(MONTH(getdate()) as VARCHAR(2))+'-'+CAST(DAY(getdate()) as VARCHAR(2))) as DateTime)
Hi @smpa01,
Since this is a direct SQL Statement, you should be able to directly use GETDATE() function as in case of SQL Server.
Did you try something like this
select [$Table].[CreatedDate] as [CreatedDate],
[$Table].[Site ID] as [Site ID]
from [dbo].[vw_xxxxxxx] as [$Table]
WHERE ([CreatedDate] between getdate() and CAST((CAST(YEAR(getdate())-2 as VARCHAR(4))+'-'+CAST(MONTH(getdate()) as VARCHAR(2))+'-'+CAST(DAY(getdate()) as VARCHAR(2))) as DateTime)
Thanks @Thejeswar it worked. You saved me. Thanks mate.
This is what I have used and it did the trick
select [$Table].[CreatedDate] as [CreatedDate]
from [dbo].[vw_xxxx] as [$Table]
WHERE [CreatedDate] >= CAST((CAST(YEAR(getdate())-2 as VARCHAR(4))+'-'+CAST(MONTH(getdate()) as VARCHAR(2))+'-'+CAST(DAY(getdate()) as VARCHAR(2))) as DateTime)
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 52 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 73 | |
| 70 | |
| 39 | |
| 34 | |
| 23 |