I’m creating an application to calculate some Login -Logouts on a call center, basically what I do is to get an interval within times.
Which would be best:
to get the interval on the DB Server (SQL Server 2000),
or in the code itself (Perl)?
I’m running on Windows Server 2003.
Basically the operation is:
Login-Logout + 1
But there are about 1 000 000 rows on each query.
P.S I do know how to do it, what I’m wondering is what would be a best practice.
This is my actual query :
select S.Ident,S.Dateissued ,
S.LoginMin,S.LogoutMin ,
E.Exc_Name ,
CAST(CAST( (LoginMin / 60 + (LoginMin % 60) / 100.0) as int ) AS varchar ) + ':' + CASE WHEN LoginMin % 60 < 10 THEN '0'+ CAST(LoginMin % 60 AS varchar) ELSE CAST(LoginMin % 60 AS varchar) END ,
CAST(CAST( (LogoutMin / 60 + (LogoutMin % 60) / 100.0) as int ) AS varchar ) + ':' + CASE WHEN LogoutMin % 60 < 10 THEN '0'+ CAST(LogoutMin % 60 AS varchar) ELSE CAST(LogoutMin % 60 AS varchar) END,
(LogoutMin-LoginMin)+1 as Mins,
E.Exc_ID,action
FROM igp_ScheduleLoginLogout S INNER JOIN igp_ExemptionsCatalog E
ON S.Exc_ID = E.Exc_ID
where ident=$ident
and dateissued between '$dateissued' and '$dateissued2'"
Short answer:
If you are doing math on a set of data (like your 1 million row example), SQL is optimized for set-based operations.
If you are doing math on an iterative, row-by-row basis, your calling application or script is probably best.