Pass minutes in int format to HH: MM SQL format

0

I'm turning trying to pass an entire value to hh:mm format.

So far I managed to do /60 , passing the rest to minutes and casting everything in string format so that I keep the : in the middle. But I would need it to be in time format to be able to do calculations:

Example:

---------------------------------------------------------------
| Legajo | PromEntMin | HoraEntrada | MinutosEntrada| Entrada |
---------------------------------------------------------------
|200     |  648       |    10       |   48          |   10:48 |
---------------------------------------------------------------
|202     |  497       |    8        |   17          |   8:17  | 
---------------------------------------------------------------
|203     |  596       |    9        |   56          |   9:56  | 
---------------------------------------------------------------

How can I format these values in SQL?

    
asked by Miamigogus 16.02.2017 в 15:33
source

2 answers

0

If you are using SqlServer 2008:

DECLARE @T TABLE (
LEGAJO INT,
PROMENT INT,
HORA INT,
MINUTO INT
)
DECLARE @TIEMPO TIME = '00:00:00'

INSERT INTO @T VALUES (200,648,10,48 )
INSERT INTO @T VALUES (202,497 ,8 ,17 )

SELECT LEGAJO, PROMENT, HORA, MINUTO,DATEADD(MINUTE, MINUTO, DATEADD(HOUR, HORA, @TIEMPO)) AS TIEMPOMANIPULABLE
FROM @T

Fiddle link: link

Thanks to @Davlio for the suggestion with TIMEFROMPARTS SqlServer 2012 - 2014:

DECLARE @T TABLE (
LEGAJO INT,
PROMENT INT,
HORA INT,
MINUTO INT
)

INSERT INTO @T VALUES (200,648,10,48 )
INSERT INTO @T VALUES (202,497 ,8 ,17 )

SELECT LEGAJO, PROMENT, HORA, MINUTO,TIMEFROMPARTS(HORA, MUNUTO, 0, 0, 0) AS TIEMPOMANIPULABLE
FROM @T

Fiddle link: link

    
answered by 16.02.2017 / 16:07
source
-1

In the case of SQLServer, for example, you have a function that will convert you a STRING into a DATETIME . With the Convert function you can do something similar to this:

UPDATE MiTabla SET MiCampo = CONVERT(datetime, '2017/02/16 10:00:00', 120)

According to the DBMS that you are using (if it is another) it is possible that something similar exists.

    
answered by 16.02.2017 в 16:04