Data type Conversion

  • I have a column with data type as int. I converted the int data type to varchar to convert nulls to N/A. As a result of this values such as 10000.00 have changed to 1000000. I need to convert the vaules back to money. Any help will be appreciated.

    Example:

    Isnull(Cast(Cast(PremiumValue as numeric) as varchar),'N/A') AS PremiumValue

  • I am not 100% sure what you mean because I can't reproduce what you're saying, but maybe one of these will help you?

    DECLARE @t TABLE (PremiumValue INT, PV MONEY)

    INSERT INTO @t

    SELECT 10000, 10000 UNION ALL SELECT NULL, NULL

    SELECT Isnull(Cast(Cast(PremiumValue as numeric) as varchar),'N/A') AS PremiumValue1

    ,Isnull(Cast(Cast(PV as numeric) as varchar),'N/A') AS PV1

    ,Isnull(Cast(Cast(PremiumValue as money) as varchar),'N/A') AS PremiumValue2

    ,Isnull(Cast(Cast(PV as money) as varchar),'N/A') AS PV2

    FROM @t

    Results are:

    PremiumValue1PV1PremiumValue2PV2

    100001000010000.0010000.00

    N/AN/AN/AN/A


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

Viewing 2 posts - 1 through 1 (of 1 total)

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