Converting a number to feet & inches

后端 未结 2 1159
不知归路
不知归路 2021-01-26 03:22

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         


        
2条回答
  •  旧巷少年郎
    2021-01-26 04:13

    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).

提交回复
热议问题