select Service,
Subscription_Number,
Order_Status,
Service_Type,
Data_Plan,
Carrier,
MDN,
Usage,
DATEADD(SECOND,ROWNUM,period_end_date) as sequence from
(
select Service,
Subscription_Number,
Order_Status,
Service_Type,
Data_Plan,
Carrier,
MDN,
Usage,
ROW_NUMBER() OVER(ORDER BY Usage ASC) as ROWNUM,
period_end_date
from
(
SELECT [Service]
,substring([Subscription_Number],8,7) Subscription_Number
,[Order_Status]
,[Service_Type]
,[Data_Plan]
,[Carrier]
,[MDN]
,round(ISNULL([Usage],0),2) Usage
,DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1) as period_end_date
FROM [dbo].[test_Usage]
where upper(Service) <> 'TOTAL'
--order by Subscription_Number desc
)A
)B
Subscription_Number,
Order_Status,
Service_Type,
Data_Plan,
Carrier,
MDN,
Usage,
DATEADD(SECOND,ROWNUM,period_end_date) as sequence from
(
select Service,
Subscription_Number,
Order_Status,
Service_Type,
Data_Plan,
Carrier,
MDN,
Usage,
ROW_NUMBER() OVER(ORDER BY Usage ASC) as ROWNUM,
period_end_date
from
(
SELECT [Service]
,substring([Subscription_Number],8,7) Subscription_Number
,[Order_Status]
,[Service_Type]
,[Data_Plan]
,[Carrier]
,[MDN]
,round(ISNULL([Usage],0),2) Usage
,DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1) as period_end_date
FROM [dbo].[test_Usage]
where upper(Service) <> 'TOTAL'
--order by Subscription_Number desc
)A
)B