Douglas Filipe
Douglas Filipe

Reputation: 77

Sum time varchar

I have this table

enter image description here

And I just need sum column Duracao + Hora to obtain a new column named Return, like this: enter image description here

In correct scenario, result of column Return must be 18:06:07. How can I get it?

Upvotes: 0

Views: 309

Answers (1)

Salman Arshad
Salman Arshad

Reputation: 272006

Assuming that Hora contains the varchar value 18:06:02 and Duracao contains the varchar value 00:00:05, you can convert them to DATETIME, then add them like so:

SELECT CONVERT(
               VARCHAR(8),
               DATEADD(
                       SECOND,
                       DATEDIFF(SECOND, 0, CAST(Duracao AS DATETIME)),
                       CAST(Hora AS DATETIME)
               ),
               108
        )

Upvotes: 1

Related Questions