Hello guys,
I have a simple Job Tracking database wherein we track a number of SitusIDs and determine which phase/status is it going through. Our Client is a bank wherein they send us deals (PK in db is SitusIDs) and we track the status of each deals in the database.
To have a quick view of the table structure: (as it relates to my question)
tblJobTracking
SitusID -- PK
WeekNumber
DealName
UBSOriginator
Broker
City
State
Region
AssetType
PropertyCount
Priority
DocLinks
tblDealStatus
DealStatusID -- PK
SitusID -- FK to tblJobTracking
Analyst
StatusChangeID -- FK to tblStatusChange
StatusDate
StatusHours
StatusComments
Now, I have a simple query that should calculate the time difference (in minutes) between when a deal has been received (Unassigned status/StatusChangeID = 1) and when it has been assigned out to someone (Assigned status/ StatusChangeID = 11)
the query is:
although I guess the query gives the correct results, it freezes the db and takes almost 10 minutes though for it to give the results when the query is being ran.
I was wondering if you could help me figure out what could have caused this or is there any way I could re-write the query to make it run faster.
Any help is greatly appreciated.
thanks
I have a simple Job Tracking database wherein we track a number of SitusIDs and determine which phase/status is it going through. Our Client is a bank wherein they send us deals (PK in db is SitusIDs) and we track the status of each deals in the database.
To have a quick view of the table structure: (as it relates to my question)
tblJobTracking
SitusID -- PK
WeekNumber
DealName
UBSOriginator
Broker
City
State
Region
AssetType
PropertyCount
Priority
DocLinks
tblDealStatus
DealStatusID -- PK
SitusID -- FK to tblJobTracking
Analyst
StatusChangeID -- FK to tblStatusChange
StatusDate
StatusHours
StatusComments
Now, I have a simple query that should calculate the time difference (in minutes) between when a deal has been received (Unassigned status/StatusChangeID = 1) and when it has been assigned out to someone (Assigned status/ StatusChangeID = 11)
the query is:
Code:
SELECT DISTINCT tblJobTracking.SitusID, tblJobTracking.DealName, (SELECT Max(StatusDate) FROM tblDealStatus WHERE StatusChangeID = 1 AND tblJobTracking.SitusID=tblDealStatus.SitusID) AS [Date Unassigned], (SELECT Min(StatusDate) FROM tblDealStatus WHERE StatusChangeID = 11 and tblJobTracking.SitusID = tblDealStatus.SitusID) AS [Date Assigned], DateDiff("n",(SELECT Max(StatusDate) FROM tblDealStatus WHERE StatusChangeID = 1 AND tblJobTracking.SitusID=tblDealStatus.SitusID),(SELECT Min(StatusDate) FROM tblDealStatus WHERE StatusChangeID = 11 and tblJobTracking.SitusID = tblDealStatus.SitusID)) AS Difference
FROM tblJobTracking INNER JOIN tblDealStatus ON tblJobTracking.SitusID = tblDealStatus.SitusID;
although I guess the query gives the correct results, it freezes the db and takes almost 10 minutes though for it to give the results when the query is being ran.
I was wondering if you could help me figure out what could have caused this or is there any way I could re-write the query to make it run faster.
Any help is greatly appreciated.
thanks