Guys..I need some help with following:
I have the following table
CREATE TABLE TBL(EQUIPMENT NVARHCAR(255),USR NVARCHAR(255), SYS_STAT NVARCHAR(255),USR_STAT NVARCHAR(255),SYS_STAT_DATE DATE,USR_STAT_DATE DATE)INSERT INTO TBL
SELECT '10013','CC_LSMW_1','Available','Active','10/18/2012','10/18/2012'
UNION
SELECT '10013','DS_CONV','Available','Procurement','10/18/2012','10/18/2012'
UNION
SELECT '10013','CC_LSMW_1','Available','Procurement','10/18/2012','10/18/2012'
UNION
SELECT '10013','BURKUN','Available','REPAIR','10/18/2012','11/15/2012'
UNION
SELECT '10013','COLES','Available','REPAIR','10/18/2012','02/07/2012'
The result should be like:
SELECT '10013','CC_LSMW_1','Available','Active','10/18/2012','10/18/2012',0
UNION
SELECT '10013','DS_CONV','Available','Procurement','10/18/2012','10/18/2012',0
UNION
SELECT '10013','CC_LSMW_1','Available','Procurement','10/18/2012','10/18/2012',0
UNION
SELECT '10013','BURKUN','Available','REPAIR','10/18/2012','11/15/2012',28
UNION
SELECT '10013','COLES','Available','REPAIR','10/18/2012','02/07/2012' ,-254
The logic is to find the datediff between the (USR_STAT_DATE where user_status is not Active) and (USR_STAT_DATE where user_status is Active)
Thank you!!