Today encountered a mistake like this, the specific error situation is as follows
The solution is as follows.
Database MSSQL When comparing the size, error prompt: "The varchar value ' 24.5 ' is converted to a column of the data type int" syntax error occurs! "The type of the Analysis database design column is varchar, and the above error is reported when the search comparison statement executes the" SELECT * from DataList where price>10 the order by id ".
As long as the price column contains decimals, there is an error, and price is a varchar type and must be converted to a numeric type.
This can be rewritten as: "SELECT * from DataList where convert (Int,convert (numeric (18,9), price)) >10 The ORDER by id"
Alternatively, you can write: "SELECT * from DataList where CONVERT (Int,cast (price as float)) >10 The ORDER by id" resolves the issue.
That is, the type of varchar is converted to numbers, and then to Int.
Another idea: When data is entered, it is possible to determine if it is an integer, and the cast, such as int (price), can also avoid errors in future SQL comparisons.
Appendix, question type Ibid.:
A syntax error occurs when SQL converts a varchar value to a column with a data type of int;
The group table has a varchar field grouppower, with a value of 1,2,3,4, and an SQL statement for
SELECT * FROM Dbo.function where
FunctionId in
(
Select Grouppower from Dbo.group
where groupid=1
)
A syntax error occurred while performing an error converting the varchar value ' 1,2,3,4 ' to a column with a data type of int.
Workaround:
Change the Where condition to:
where CHARINDEX (RTrim (functionId), (select top 1 grouppower from Loan_group where groupid=1)) >0
Syntax error occurred while resolving SQL converting varchar values to columns with data type int