Convert nvarchar to numeric

  • I am trying to do an insert from one table to another where for one column the destination table expects a numerice value while the source table column is a nvarchar(MAX). So I receive an Error converting data type nvarchar to numeric. How can I solve this issue?

    INSERT INTO dbo.TABLE1

    (

    Name

    , LastDate

    , Price

    )

    SELECT

    Name = item_name

    , LastDate = getdate()

    , Price = field1

    FROM TABLE2

    Column Price is a decimal(18,5) and column field1 is a nvarchar(MAX).

    Thanks.

  • can you convert it to decimal?

    'price' = convert(decimal(18,5),field1)

  • When I try to convert to int CONVERT (INT, field1) I get the following message:

    Conversion failed when converting the nvarchar value '15.500' to data type int.

  • OJDev (4/16/2009)


    When I try to convert to int CONVERT (INT, field1) I get the following message:

    Conversion failed when converting the nvarchar value '15.500' to data type int.

    This is because the INT datatype only supports whole numbers, to convert 15.500 you will need to choose a data type that supports decimals such as Numeric..

  • sorry, you must have read my post before i edited it. my previous post on here is correctly showing as a convert to decimal now.

  • actually, while i'm here, why do i have a delete button available on this forum for the posts of other people? if i click to delete someone elses posts will it delete or will it just deny me?

  • Lately, it won't even let you delete your own post.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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