Showing posts with label figure. Show all posts
Showing posts with label figure. Show all posts

Thursday, March 29, 2012

converting decimal to time

how do you convert a numeric to time format if it shows hours but a decimal figure for Minutes. For example if I have hours in decimal format like this

28.5000

but I want to show it in this format:

28:30:00

where 28 = hours, 30 = minutes, 00 = seconds

Thanks.This is a presentation issue. It should be handled at the client, not the server. Dealing with formatting inside the database is just a recipe for problems later.

-PatP|||What Pat said

DECLARE @.hours decimal(15,4)
SELECT @.hours = 28.5
SELECT RIGHT('00' + CONVERT(varchar(2),FLOOR(@.hours)),2)
+':'
+ RIGHT('00' + CONVERT(varchar(2),FLOOR(((@.hours-FLOOR(@.hours))*60))),2)
+':'
+ RIGHT('00' + CONVERT(varchar(2),FLOOR(((@.hours-FLOOR(@.hours))*60)-FLOOR(((@.hours-FLOOR(@.hours))*60)))*60),2)|||Displaying it as 28:30:00 is a presentation issue, but converting it to a valid datetime format falls within the scope of the database server:declare @.Hours decimal (6, 4)
set @.Hours = 28.5
select dateadd(minute, @.Hours * 60, 0)|||I was gonna give them that, but I realized it wasn't what they asked for...

Hours of what BTW...sounds like derived data gotta be careful with that

Sunday, February 19, 2012

Convert INT value to STRING so I can add it to another STRING

I'm trying to figure out how to convert an INT so that I can add it to another string in a statement like
SELECT '<a href="http://links.10026.com/?link=http://mydomain.com/' + [IntValue] + '">' + [LinkName]
Where [IntValue] is an INT field containing a folder number. I tried:

TO_CHAR([IntValue, '999')
but it didn't work. And I tried to find a TO_STRING function, but had no luck.
Any advice to someone who is savy, but new to SQL Queries?

SELECT '<a href="http://links.10026.com/?link=http://mydomain.com/' + STR([IntValue]) + '">' + [LinkName]
HTH
regards

|||Bingo! I had to restrict the function to 3 digits for my purposes, but it worked like a charm.
Thanks a bunch!