I have 2 dates, StartDate and EndDate:
Declare @StartDate date='2018/01/01', @Enddate date ='2018/12/31'
Then there is some data with a date and value in a mytable table:
----------------------------
ID date value
----------------------------
1 2018/02/14 4
2 2018/09/26 7
3 2017/09/20 2
data maybe start before 2018 and if it exist before @startdate get before values else get 0 I'm looking to get a result that looks like this:
-----------------------------------
fromdate todate value
-----------------------------------
2018/01/01 2018/02/13 2
2018/02/14 2018/09/25 4
2018/09/26 2018/12/31 7
The first fromdate comes from @StartDate and the last todate is from @Enddate, and the other data should be generated.
I'm hoping to get this in an SQL query. I use sql-server 2016