Share via

Sql Server

Andre Talon 20 Reputation points
2023-08-17T03:55:36.04+00:00

Olá pessoal boa noite !

Preciso de uma ajuda , no sql server eu tenho um campo de horas que em instante ele está como 701 e instante 1501 preciso preencher e converter para 07:01 e 15:01 como faço isso ?

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Answer accepted by question author

LiHongMSFT-4306 31,621 Reputation points
2023-08-18T01:51:21.22+00:00

Hi @Andre Talon

Please check this:

Declare @table table( FIELD int)
Insert into @table values
(701),(1501)

SELECT STUFF(RIGHT(CONCAT('0000',FIELD),4),3,0,':') AS NewField
FROM @table

Best regards,

Cosmog Hong


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Andre Talon 20 Reputation points
    2023-08-18T02:56:37.0433333+00:00
    Perfect !
    Thanks for the support, simple as that.
    I just needed to pad with 0 to the left of the hour and add the :
    

    Was this answer helpful?

    0 comments No comments

  2. Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
    2023-08-17T22:11:49.22+00:00

    Your question is not very clear - and I don't think this only due to that Portuguese is a language I don't master very well - but you could try

    SELECT dateadd(HOUR, 8, campo)
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.