Is there anyway to make an integer field retain its leading zeros? In a transformation process one of my procedures has to change a time into an integer so any time that is only minutes 0023 is coming through as 23.
An integer field stores only the numeric value of a number. Displaying leading zeros is a formatting issue and has to be dealt with when the number is printed out. An integer field will store 23 and 0023 in exactly the same way, theres no way you can change this. You could store the number as a string field if you want to preserve leading zeros, or you could add them when you print out the number.
here is the catch. It's not for printing I am actually calculating a time and because the field is imported as an integer it is seeing any time less the 0100 (example 0023)as 23 hours instead of 23 minutes.........recommendation on handling?
takes a base date (presumably 00:00) and adds the appropriate number of minutes and hours to it. Updates a column in tblDates called Date with the basedate + the appropriate number of hours and minutes, represented in the column intfield.
DECLARE @BaseDate datetime
SET @BaseDate = whatever
Update tblDates
SET Date = dateadd(mi, right(cast(intfield as varchar), 2), dateadd(hh, intfield/100, @BaseDate))
The STR function is handy because it right justifies whereas convert and cast to char or varchar left justifies the number. If you want to get the best answer for your question read faq183-874.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.