question

sweta.dutta7 avatar image
sweta.dutta7 asked

Sales figure in pence to £ and p

Ok I know there is a function but being out of work for a bit has left me with some blanks :( Simple qry sales amount stored in pence and need to convert it to £ and pence.Simply dividing it by 100 isn't helping. 19250 -> 192.50 10240 -> 102.40 Help please !
sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered
It's probably because you are doing integer division. Try select 19250/100.00
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sweta.dutta7 avatar image sweta.dutta7 commented ·
Hi Kev, when using [sales]/100.00 its retaining the pence value but adding extra trailing zeros 7512 -> 75.120000 How can I get rid of trailing zeros ? I remember using decimal fn sometime back to get rid of trailing zeros. Let me check if that helps else your advice will be very much helpful.
0 Likes 0 ·
sweta.dutta7 avatar image sweta.dutta7 commented ·
Not to worry...the following worked wonders convert(decimal(8,2),[sales]/100.00). Thanks all!
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
That's what would have suggested. Glad you found it.
0 Likes 0 ·
tanglesoft avatar image
tanglesoft answered
Does this help select 19250 / 100 select 19250 % 100
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
+1 ahh I see a different interpretation of the question.
0 Likes 0 ·
sweta.dutta7 avatar image sweta.dutta7 commented ·
The value is stored as a column in a table. E.g.- If I do [sales]/100 its converting 7512 to 75 when ideally it should be 75.12 If I use [sales]%100 , its converting 7512 to 12 [sales] column is stored as an interger. Let me know if you need more info.
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
What @tanglesoft is saying is that if you needed 2 fields from one, i.e. pounds ***and*** pence, then the integer division and integer remainder (modulo function %) would get you that.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.