Professional Web Applications Themes

Best CAST resolution for converting ... - Microsoft SQL / MS SQL Server

I need to convert a string to currency. Is it best to use money or decimal (18,0)? The field in the table is currently decimal (18, 0) but I get an error trying to directly cast nvarchar(20) to decimal (18, 0). Suggestions?...

  1. #1

    Default Best CAST resolution for converting ...

    I need to convert a string to currency.

    Is it best to use money or decimal (18,0)?

    The field in the table is currently decimal (18, 0) but
    I get an error trying to directly cast nvarchar(20) to
    decimal (18, 0).

    Suggestions?
    randyv Guest

  2. #2

    Default Re: Best CAST resolution for converting ...

    Better to use Money but it depends on your business rules.
    You should not have a problem converting nvarchar to decimal or money.
    What problem are you having?
    Give an example of what you are trying to do.

    "randyv" <com> wrote in message
    news:01c801c365aa$d85a5430$gbl... 


    raydan Guest

  3. #3

    Default Re: Best CAST resolution for converting ...

    > The field in the table is currently decimal (18, 0) but 

    What is the error message? What is the nvarchar(20) value you are trying to
    convert? Show your syntax?

    Since the possibilities are so broad, you might find you get better results
    if you supply specific symptoms/data rather than vague narrative.


    Aaron Guest

  4. #4

    Default Re: Best CAST resolution for converting ...

    Randy,

    You might want to check to see if the varchar can be converted to a numeric.
    You might have some dirty data in the column.

    SELECT
    CASE
    WHEN ISNUMERIC(your_column) = 1 THEN CONVERT( DECIMAL (18,2),
    your_column)
    ELSE NULL -- or zero, or -1 to indicate an error, or any other
    number to indicate a non-convertable string
    END
    your_column_name_alias
    FROM your_table

    This doesn't guarantee that you will get the results you want. If the
    converted value would overflow your datatype, then you will still get an
    error, even though it is a numeric.

    Hope this helps.

    Bill

    "randyv" <com> wrote in message
    news:01c801c365aa$d85a5430$gbl... 


    Alter Guest

  5. #5

    Default Re: Best CAST resolution for converting ...

    > WHEN ISNUMERIC(your_column) = 1 THEN CONVERT( DECIMAL (18,2), 

    And you could still get a conversion error, e.g. if you had '2e4' in
    your_column...


    SELECT ISNUMERIC('2e4')
    -----------
    1


    SELECT CONVERT(DECIMAL(18,2), '2e4')
    -----------
    Server: Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.


    See isReallyNumeric / isReallyInteger:
    http://www.aspfaq.com/2390


    Aaron Guest

Similar Threads

  1. Replies: 1
    Last Post: November 7th, 02:18 AM
  2. Changing Monitor Resolution/Screen Resolution
    By chouhdry in forum Macromedia Director Lingo
    Replies: 2
    Last Post: February 17th, 05:29 PM
  3. cast members moved in cast - neet to get htem back!!!
    By spdorsey webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 2
    Last Post: November 24th, 08:48 PM
  4. changing the cast number of a cast at authoring time?
    By david taylor in forum Macromedia Director Basics
    Replies: 0
    Last Post: November 21st, 05:41 AM
  5. Converting multiple sprites into a new cast member
    By zen5q webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: August 29th, 10:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139