Need Urgent help to convert nVarchar to Numeric in SQL

  • Dear friends,

    I have field "Monthly_Cost" in DB that is nVRACHAR - with value '2094', how to convert it into a NUMERIC value please? Please advice with an example.

    thanks

    DJ

  • DJ

    What have you tried already? Have you read the "CAST and CONVERT" topic in Books Online?

    John

  • Try something like this.

    xtable has test column with datatype nvarchar.

    select test from xtable

    Output:

    test

    1

    2

    3

    select CONVERT (int, xtable.test) from xtable

    Output:

    1

    2

    3

  • Are you talking about converting the values in a sql script or actually changing the data type of the field in the table?

    Let us know what you've tried already. Samples of what you did, what you're trying to get to etc...

    Link in my sig on how to ask for help the right way.

    ---------------------------------------------------------------
    Mike Hahn - MCSomething someday:-)
    Right way to ask for help!!
    http://www.sqlservercentral.com/articles/Best+Practices/61537/
    I post so I can see my avatar :hehe:
    I want a personal webpage 😎
    I want to win the lotto 😀
    I want a gf like Tiffa :w00t: Oh wait I'm married!:-D

  • Hi John,

    I was confused between CAST and CONVERT which one to use finally I ended up using CAST.

    If you can explain in simple words the difference to me would be much appreciated please

    thanks

    DJ

  • You seem to have a a few basic questions that sound a lot like test/homework questions. I think this is your 2nd question on CAST/CONVERT issue, If you need to know the difference between the 2 I'd suggest reading Books online or google "CAST vs CONVERT SQL Server".

    Not to knock anyone or say we don't like to help.

    I've found the people on here very helpful as long as I'm willing to put in the time to do some research on my end. You'll find that most people will ask "what have you tried" or "post your sample code".

    I personally don't like helping people with their homework or do their jobs for them.

    ---------------------------------------------------------------
    Mike Hahn - MCSomething someday:-)
    Right way to ask for help!!
    http://www.sqlservercentral.com/articles/Best+Practices/61537/
    I post so I can see my avatar :hehe:
    I want a personal webpage 😎
    I want to win the lotto 😀
    I want a gf like Tiffa :w00t: Oh wait I'm married!:-D

  • no worries I figured it out BTW I come from Java world and always teach and preach also that's why I'm successful 🙂 I did not ask you to do my work 🙂 just asked for advise/expert judgement.

    thanks

    Dhananjay

  • dhananjay.nagarkar (8/15/2013)


    I was confused between CAST and CONVERT which one to use finally I ended up using CAST.

    If you can explain in simple words the difference to me would be much appreciated please

    They are equivalent more or less. CAST is ANSI-compliant, while CONVERT is older and proprietary. CONVERT takes a third parameter for some conversions which is not available with CAST.

    Myself I tend to mix both at whim, but I probably use CONVERT far more than CAST.

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]

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

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