Click here to Skip to main content
15,889,116 members
Home / Discussions / Database
   

Database

 
QuestionUpdating Database through datagrid Pin
Raheem MA4-Apr-07 1:22
Raheem MA4-Apr-07 1:22 
AnswerRe: Updating Database through datagrid Pin
joon vh.4-Apr-07 1:26
joon vh.4-Apr-07 1:26 
GeneralRe: Updating Database through datagrid Pin
Raheem MA4-Apr-07 1:37
Raheem MA4-Apr-07 1:37 
QuestionTransactions in a stored procedure Pin
gauthee4-Apr-07 1:20
gauthee4-Apr-07 1:20 
AnswerRe: Transactions in a stored procedure Pin
joon vh.4-Apr-07 1:35
joon vh.4-Apr-07 1:35 
AnswerRe: Transactions in a stored procedure Pin
andyharman4-Apr-07 3:14
professionalandyharman4-Apr-07 3:14 
QuestionHow to Execute the DTS Package from C#.net Code Behind? Pin
SrinivasanPrabakaran4-Apr-07 0:51
SrinivasanPrabakaran4-Apr-07 0:51 
QuestionConverting seconds to hours and mins Pin
si_694-Apr-07 0:43
si_694-Apr-07 0:43 
Hi All

Perhaps someone can advise on a better solution to my problem ?

I have a table full of call (telephone) records, each record has the duration of the call made

the duration is in seconds

i.e

Call table

Call id, duration, telephonenumber
1 89 0122222222222
2 135 0192929292929
3 31 0121122211111
4 5....etc etc


what i need to do i go through each record and convert the duration to a time format

so
for call id 1, the result would be 01:29,
for 2, result would be 02:15
for 3, result would be 00:31
for 4, result would be 00:05

at the moment, below is what i am doing within a cursor for each row, and although it works fine

it is a really slow way of doing things, and when i have to go through a few million records you can imagine this takes quite a while

Can anyone suggest a quicker alternative ?

Hope that all makes sense ?

Simon

set @CounterVariable = 1
set @hours = 0
set @mins = 0
set @time_counter = 0


WHILE (@CounterVariable <= @dur)
BEGIN --- count the hours
set @CounterVariable = @CounterVariable + 1
set @time_counter = @time_counter +1
IF @time_counter = 60
BEGIN
set @hours = @hours + 1
set @time_counter = 0
END

END
--- mins is remainder (seconds)
set @mins = @time_counter

IF @hours < 10 and @time_counter < 10 -- build the time string
BEGIN
set @dur_time = '0'+ CAST(@hours as varchar(2)) + ':' + '0' + CAST(@mins as varchar(2))
END
ELSE IF @hours >= 10 and @time_counter < 10
BEGIN
set @dur_time = CAST(@hours as varchar(2)) + ':' + '0' + CAST(@mins as varchar(2))
END
ELSE IF @hours < 10 and @time_counter>= 10
BEGIN
set @dur_time = '0'+ CAST(@hours as varchar(2)) + ':' + CAST(@mins as varchar(2))
END
ELSE IF @hours >=10 and @time_counter>= 10
BEGIN
set @dur_time = CAST(@hours as varchar(2)) + ':' + CAST(@mins as varchar(2))
END

AnswerRe: Converting seconds to hours and mins Pin
Hayder Marzouk4-Apr-07 2:13
Hayder Marzouk4-Apr-07 2:13 
AnswerRe: Converting seconds to hours and mins Pin
DQNOK4-Apr-07 8:40
professionalDQNOK4-Apr-07 8:40 
GeneralRe: Converting seconds to hours and mins Pin
si_695-Apr-07 0:50
si_695-Apr-07 0:50 
QuestionSQL Server Management Studio Express Pin
Zalro3-Apr-07 23:24
Zalro3-Apr-07 23:24 
AnswerRe: SQL Server Management Studio Express Pin
originSH5-Apr-07 0:51
originSH5-Apr-07 0:51 
QuestionCustom Replication / Mirroring for SQL Server 2005 Express Pin
Ligblou3-Apr-07 21:30
Ligblou3-Apr-07 21:30 
QuestionMS Access as Database and SQL: Problem in WHERE clause Pin
santoshsan3-Apr-07 21:20
santoshsan3-Apr-07 21:20 
AnswerRe: MS Access as Database and SQL: Problem in WHERE clause Pin
Adeel Chaudhry3-Apr-07 21:34
Adeel Chaudhry3-Apr-07 21:34 
GeneralRe: MS Access as Database and SQL: Problem in WHERE clause Pin
Colin Angus Mackay3-Apr-07 21:38
Colin Angus Mackay3-Apr-07 21:38 
GeneralRe: MS Access as Database and SQL: Problem in WHERE clause Pin
santoshsan3-Apr-07 23:15
santoshsan3-Apr-07 23:15 
GeneralRe: MS Access as Database and SQL: Problem in WHERE clause Pin
santoshsan3-Apr-07 22:54
santoshsan3-Apr-07 22:54 
AnswerRe: MS Access as Database and SQL: Problem in WHERE clause Pin
Colin Angus Mackay3-Apr-07 21:37
Colin Angus Mackay3-Apr-07 21:37 
GeneralRe: MS Access as Database and SQL: Problem in WHERE clause Pin
santoshsan3-Apr-07 23:09
santoshsan3-Apr-07 23:09 
AnswerRe: MS Access as Database and SQL: Problem in WHERE clause Pin
ChandraRam4-Apr-07 0:17
ChandraRam4-Apr-07 0:17 
Questionproblem when creating database independant access layer Pin
Hassan Amaar3-Apr-07 21:11
Hassan Amaar3-Apr-07 21:11 
AnswerRe: problem when creating database independant access layer Pin
Paddy Boyd3-Apr-07 23:55
Paddy Boyd3-Apr-07 23:55 
GeneralRe: problem when creating database independant access layer Pin
Hassan Amaar5-Apr-07 1:49
Hassan Amaar5-Apr-07 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.