Converting money field

  • In the sql below, column pol_fac_at is defined as dataype money. For a value of $5113.40, it is being returned in the select as 5113.4000

    I want it to be returned as 00000511340.

    How can I get that? Any help is greatly appreciated.

    thanks!

    SELECT top 10

    VIEW_RepRatio_NewPolicy_Agent.pol_fac_at

    FROM

    VIEW_RepRatio_NewPolicy_Agent

  • How do you know where the decimal starts?

    Also I feel I must mention that this presentational stuff should be made at the client.

    But if you insist on doing it on the server :

    Declare @x as money

    set @x = 5113.4

    select @x

    Select RIGHT('00000000000' + REPLACE(CAST(@X as varchar(9)), '.', ''), 11)

    --00000511340

    Please retest this with your data because I'm not sure it'll always work.

  • One might be inclined to think, that this is presentational stuff done best at the client. Anyway, piggy-backing on Remi, here's another method

    SELECT REPLACE(STR(@x*100,11), ' ', '0')

    for the lazycoder.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Quoting myself :

    "Also I feel I must mention that this presentational stuff should be made at the client."

    .

  • Thanks Frank and Remi! I appreciate the help.

  • HTH.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply