Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert height in inches to feet and inches 1

Status
Not open for further replies.
Jun 27, 2001
837
US
Has anyone attempted to convert in TSQL inches to Feet and inches. For example take 74 inches and convert to 6ft 2 inches? I was thinking about a case but that seems a little cumbersome
 
I don't think you need a CASE statement. How does this work for you? HTH, Good luck!

Code:
DECLARE @inches int
SET @inches = 74

SELECT CAST((@inches / 12) AS varchar(10)) + ' ft '
       + CAST((@inches % 12) AS varchar(10)) + ' in'

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
thanks works great, just out of curiousity, what does the
%12 do?
 
The percent sign is the modulo operator. It returns the remainder of a division operation. If you divide 74 by 12 the modulo is 2.

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top