Home Forums SQL Server 2012 SQL 2012 - General How do i change a string key to an int - normal methods not working! RE: How do i change a string key to an int - normal methods not working!

  • isuckatsql (4/13/2014)


    did VARCHAR(20)

    SELECT top 10 CAST(did AS INT) FROM table

    Msg 245, Level 16, State 1, Line 3

    Conversion failed when converting the varchar value 'cht6p575l7ry61k1npt' to data type int.

    SELECT CONVERT(INT, did) FROM table

    Msg 245, Level 16, State 1, Line 5

    Conversion failed when converting the varchar value 'cht6p575l7ry61k1npt' to data type int.

    I found a SQL Function that removes all the alphabetic characters from the string and just leaves the integers.

    Is that the only solution ?

    Thanks

    Quick question, what is the integer representation for? Unless this is a number of base 35 or 36, I cannot see any obvious and meaningfull conversion.:cool: