Hi,
i am troubling with the issue that i have made one stored procedure which will returns data based on the datetime and it works fine but at the time of data insertion process is going ( insertion of new row with latest updated datetime ) on that
time stored proc will fetch wrong data or half of the data and once insertion process is complete after a some period of time data will come as what i expect to be..
to resolved this issue i found Table Hint i.e (NOLOCK) and i tried that also but that was also fetching same..
so please suggest me if there is having any more things to fetch the data correctly without troubling if at the same time
data insertion process is going.
If You Need here is my stored procedure.
SELECT SUM(FINAL.TOTALTERMINALCOUNT) TOTALTERMINALCOUNT,SUM(FINAL.LIVEWITHOUTFAULT) LIVEWITHOUTFAULT,
SUM(FINAL.LIVEWITHFAULT) LIVEWITHFAULT,SUM(FINAL.DOWN) DOWN FROM
(SELECT COUNT( STEP1.SSTID) AS TOTALTERMINALCOUNT,0 AS LIVEWITHOUTFAULT,0 AS LIVEWITHFAULT,0 AS DOWN FROM
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetDateXMLLandingOnSSTID(sstmaster_cdms.sstid) as xmlDate
from sstmaster_cdms left outer join xml_landing_summary
on sstmaster_cdms.sstid=xml_landing_summary.sstid) as STEP1
left outer join
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetPrblmDateTroubleTicketDetailOnSSTID(sstmaster_cdms.sstid) as ProblemStatus
from sstmaster_cdms
left outer join TroubleTicketDetail_SHMS
on sstmaster_cdms.sstid=TroubleTicketDetail_SHMS.sstid) AS STEP2
ON STEP1.SSTID=STEP2.SSTID
UNION
SELECT 0 AS TOTALTERMINALCOUNT,COUNT(STEP1.SSTID) AS LIVEWITHOUTFAULT,0 AS LIVEWITHFAULT,0 AS DOWN FROM
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetDateXMLLandingOnSSTID(sstmaster_cdms.sstid) as xmlDate
from sstmaster_cdms left outer join xml_landing_summary
on sstmaster_cdms.sstid=xml_landing_summary.sstid) as STEP1
left outer join
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetPrblmDateTroubleTicketDetailOnSSTID(sstmaster_cdms.sstid) as ProblemStatus
from sstmaster_cdms
left outer join TroubleTicketDetail_SHMS
on sstmaster_cdms.sstid=TroubleTicketDetail_SHMS.sstid) AS STEP2
ON STEP1.SSTID=STEP2.SSTID
WHERE (DATEDIFF(mi,CONVERT(datetime,STEP1.xmldate , 108),CONVERT(datetime, GETDATE(), 108))<120
AND DATEDIFF(mi,CONVERT(datetime,STEP1.xmldate , 108),CONVERT(datetime, GETDATE(), 108))>0)
AND (STEP2.ProblemStatus ='CLOSE' OR STEP2.ProblemStatus IS NULL)
UNION
SELECT 0 AS TOTALTERMINALCOUNT,0 AS LIVEWITHOUTFAULT,COUNT(STEP1.SSTID) AS LIVEWITHFAULT,0 AS DOWN FROM
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetDateXMLLandingOnSSTID(sstmaster_cdms.sstid) as xmlDate
from sstmaster_cdms left outer join xml_landing_summary
on sstmaster_cdms.sstid=xml_landing_summary.sstid) as STEP1
left outer join
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetPrblmDateTroubleTicketDetailOnSSTID(sstmaster_cdms.sstid) as ProblemStatus
from sstmaster_cdms
left outer join TroubleTicketDetail_SHMS
on sstmaster_cdms.sstid=TroubleTicketDetail_SHMS.sstid) AS STEP2
ON STEP1.SSTID=STEP2.SSTID
WHERE (DATEDIFF(mi,CONVERT(datetime,STEP1.xmldate , 108),CONVERT(datetime, GETDATE(), 108))<120
AND DATEDIFF(mi,CONVERT(datetime,STEP1.xmldate , 108),CONVERT(datetime, GETDATE(), 108))>0)
AND (STEP2.ProblemStatus <>'CLOSE')
UNION
SELECT 0 AS TOTALTERMINALCOUNT,0 AS LIVEWITHOUTFAULT,0 AS LIVEWITHFAULT,COUNT(STEP1.SSTID) AS DOWN FROM
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetDateXMLLandingOnSSTID(sstmaster_cdms.sstid) as xmlDate
from sstmaster_cdms left outer join xml_landing_summary
on sstmaster_cdms.sstid=xml_landing_summary.sstid) as STEP1
left outer join
(select distinct(sstmaster_cdms.sstid) as sstid,dbo.GetPrblmDateTroubleTicketDetailOnSSTID(sstmaster_cdms.sstid) as ProblemStatus
from sstmaster_cdms
left outer join TroubleTicketDetail_SHMS
on sstmaster_cdms.sstid=TroubleTicketDetail_SHMS.sstid) AS STEP2
ON STEP1.SSTID=STEP2.SSTID
WHERE (DATEDIFF(mi,CONVERT(datetime,STEP1.xmldate , 108),CONVERT(datetime, GETDATE(), 108))>120
AND DATEDIFF(mi,CONVERT(datetime,STEP1.xmldate , 108),CONVERT(datetime, GETDATE(), 108))>0)
OR STEP1.xmldate IS NULL
) AS FINAL