Manupilating previous month data according to current month

南笙酒味 提交于 2019-12-01 14:41:36

To me also it appear that you are not covering your requirement very well.

I have not followed a thing.

Only thing I understood is that you want to convert Cur_Month data into Cur_Data bease on certain format.I have not understood the background.

try this and let me know,

declare @Prv_Data table(Report_ID int,Timeline varchar(40))
insert into @Prv_Data VALUES
(01,'Weekly @Mon')
,(01,'Weekly @Mon')
,(01,'Weekly @Mon')
,(01,'Weekly @Mon')
,(02,'Weekly @Thru')
,(02,'Weekly @Thru')
,(02,'Weekly @Thru')
,(02,'Weekly @Thru')
,(02,'Weekly @Thru')


declare @Cur_Month table(Details varchar(40),Count varchar(40))
insert into @Cur_Month VALUES
('First Date','05/01/2017')
,('Last Date','05/31/2017')
,('Friday','4')
,('Monday','5')
,('Saturday','4')
,('Sunday','4')
,('Thursday','4')
,('Tuesday','5')
,('Wednesday','5')
;WITH Cur_Data as
(
select *
,case when Details='Monday' then '1' 
when Details='Thursday' then '2'  END ReportID
,case when Details='Monday' then 'Weekly @Mon' 
when Details='Thursday' then 'Weekly @Thru'  END Timeline
  from @Cur_Month
where Details in('Monday','Thursday')
)

select REPLICATE('0',len(ReportID))+  ReportID ReportID
,Timeline from Cur_Data c
cross apply  (select number 
from master..spt_values where number>0 
and number<=c.[count]  and type='LO')cs
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!