can you guys help me, I always get this error when importing management studio sql files.

muhammad fajar 0 Reputation points
2024-05-30T08:14:13.89+00:00

The given value '24,269' of type String from the data source cannot be converted to type int for Column 7 [rating_count]. (Microsoft.Data.SqlClient)


Failed to convert parameter value from a String to a Int32. (Microsoft.Data.SqlClient)


Input string was not in a correct format. (mscorlib)

SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 47,516 Reputation points
    2024-05-30T08:33:48.96+00:00

    cannot be converted to type int

    As the message says.

    You have a numeric in de-DE format looking string, it can't be implicit converted into integer.

    You have to replace the comma with a dot to get a valid en-US formatted numeric, then you can first convert to numeric and that to integer, see

    https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-type-conversion-database-engine?view=sql-server-ver16

    Example

    DECLARE @test varchar(100) = '24,269'
    
    -- Returns NULL = invalid
    SELECT TRY_CONVERT(int, @test)
    -- Returns 24 = valid
    SELECT TRY_CONVERT(int, TRY_CONVERT(float, REPLACE(@test, N',', N'.')))
    
    
    0 comments No comments

  2. ZoeHui-MSFT 41,496 Reputation points
    2024-05-31T02:18:39.5233333+00:00

    Hi @muhammad fajar

    The given value '24,269' of type String from the data source cannot be converted to type int for Column 7 [rating_count]

    From the error message, it is a clear issue that the datatype between the columns do not match.

    You may need to change the datatype of your source column or the destination column.

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.