I want to take a number from a table ( using sql server 2008 ) such as 720 and convert it to feet and inches with this:
Format(Val(Length) \\ 12, \"00\' \") &a
Although you can use format()
for this, it is not necessary.
When creating strings with a particular format, I like to use replace()
with wildcards in the string. This lets me easily control the format to see what is being produced:
select replace(replace(''' "',
'', val(length) / 12),
'', val(length) % 12)
This assumes that the expression val(length)
returns an integer. If the column is just called length, then you would use length
instead of val(length)
.