Hi @Mel Buckner ,
Welcome to the Microsoft TSQL Q&A Forum!
As ErlandSommarskog mentioned, because you did not provide relevant data and expected results, we are temporarily unable to provide you with advice. But according to your description, I wrote an example, which may be useful to you:
create table #test(today date)
insert into #test values('2021-01-01'),('2020-12-21'),('2020-12-01'),('2020-10-01')
,('2021-01-02'),('2020-12-22'),('2020-12-02'),('2020-10-02')
;with cte
as(select today,DATEBUCKET,case when DATEBUCKET between 0 and 30 then 1
when DATEBUCKET between 31 and 45 then 2
when DATEBUCKET between 46 and 60 then 3
when DATEBUCKET >60 then 4 end rn
from (select today,DATEDIFF(DAY,today,GETDATE()) DATEBUCKET from #test) t)
select today,DATEBUCKET,case when rn=1 then DATEBUCKET end [0-30 days],
case when rn=2 then DATEBUCKET end [31-45 days],
case when rn=3 then DATEBUCKET end [46-60 days],
case when rn=4 then DATEBUCKET end [60+ days]
from cte
Output:
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
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.