SQL experiment verifies data type conversion to implement SQL statements
SQL experiment verifies data type conversion to implement SQL statements
-
Declare @ I int
Set @ I = 'A'
Set @ I = cast ('A' as int)
Set @ I = convert (int, 'A ')
Print @ I-- Syntax error occurs when the varchar value 'a' is converted to an int column. This is different from java.
-
Declare @ ch varchar (90)
Set @ ch = 97
Print @ ch
-- The result is 97, which indicates that it is implicitly converted to a string.
-
Declare @ ch varchar (90)
Set @ ch = 97 + 'A'
Print @ ch
-- Syntax error occurs when the varchar value 'a' is converted to an int column. Why don't I convert the number 97 to a string and connect it with 'A' first? Is it because SQL Server tries to do this because 97 is in the front? Change location to see
-
Declare @ ch varchar (90)
Set @ ch = 'A' + 97
Print @ ch
-- Syntax error occurs when the varchar value 'a' is converted to an int column. I don't understand why SQL Server Always converts 'A' to a number, leading to a failure.