SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to convert kilograms to pounds and ounces


How to convert kilograms to pounds and ounces

Author
Message
NineIron
NineIron
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10262 Visits: 868
I'm need to convert kilograms to pounds and ounces. See attached data.


create table #T

(

ID,

Weight decimal(10,2)

)

insert into #T(ID,PtWeight) values(1,58.3)

insert into #T(ID,PtWeight) values(2,45.3)

insert into #T(ID,PtWeight) values(3,64.5)

insert into #T(ID,PtWeight) values(4,52.2)

insert into #T(ID,PtWeight) values(5,63.2)

insert into #T(ID,PtWeight) values(6,65.4)

insert into #T(ID,PtWeight) values(7,71.2)

insert into #T(ID,PtWeight) values(8,85.6)

insert into #T(ID,PtWeight) values(9,25.5)

insert into #T(ID,PtWeight) values(10,26)

insert into #T(ID,PtWeight) values(11,45.9)

insert into #T(ID,PtWeight) values(12,76.4)



John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)

Group: General Forum Members
Points: 130819 Visits: 19097
Multiply by 2.2 to convert to pounds and multiply the resulting decimal part by 16 to get the ounces.

John
ScottPletcher
ScottPletcher
SSC Guru
SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)

Group: General Forum Members
Points: 82900 Visits: 9356
Or perhaps multiply by 2.2046226218, or some shorter variant of that, if you need more accuracy. 2.2 is rather rough estimate.

SQL DBA,SQL Server MVP(07, 08, 09) Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial:
If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)

Group: General Forum Members
Points: 130819 Visits: 19097
ScottPletcher - Friday, December 29, 2017 8:18 AM
Or perhaps multiply by 2.2046226218, or some shorter variant of that, if you need more accuracy. 2.2 is rather rough estimate.

Understood. I thought of looking up the exact number, but then I figured that the original poster is just as capable of doing that as I am.

John

ScottPletcher
ScottPletcher
SSC Guru
SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)SSC Guru (82K reputation)

Group: General Forum Members
Points: 82900 Visits: 9356
John Mitchell-245523 - Friday, December 29, 2017 8:23 AM
ScottPletcher - Friday, December 29, 2017 8:18 AM
Or perhaps multiply by 2.2046226218, or some shorter variant of that, if you need more accuracy. 2.2 is rather rough estimate.

Understood. I thought of looking up the exact number, but then I figured that the original poster is just as capable of doing that as I am.

John

Idk, if OP was willing to do that, would prob never have asked the q to begin with BigGrin


SQL DBA,SQL Server MVP(07, 08, 09) Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial:
If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.
NineIron
NineIron
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10262 Visits: 868
Thanx but, how can I get the decimal part to multiply by 16. I think it has something to do with "%".
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)

Group: General Forum Members
Points: 130819 Visits: 19097
No, just subtract the integer part, which you get by using FLOOR.

John
NineIron
NineIron
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10262 Visits: 868
Given a weight of 68.6 kg. Is this the best way to do it?

select concat(floor((68.6*2.2)),' lbs ',((68.6*2.2)%1)*16,'oz') as PtWeight


John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)SSC Guru (130K reputation)

Group: General Forum Members
Points: 130819 Visits: 19097
You don't want to do the calculation twice if you don't have to. Try this:

SELECT CONCAT(F.FloorWeight,'lbs ',(W.WeightinPounds - F.FloorWeight)*16,'oz') as PtWeight
FROM #T t
CROSS APPLY (
SELECT t.PtWeight * 2.2
) W(WeightinPounds)
CROSS APPLY (
SELECT FLOOR(W.WeightinPounds)
) F(FloorWeight)


John
NineIron
NineIron
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10262 Visits: 868
Thanx. Happy New Year.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search