SQL Server data type Conversion small experiment _mssql

Source: Internet
Author: User
  1.   DECLARE @i int
    Set @i= ' a '
    Set @i=cast (' a ' as int)
    Set @i=convert (int, ' a ')
    Print @i--The output is: syntax error occurs when converting varchar value ' A ' to a column with a data type of int. This is not the same as Java

  2. DECLARE @ch varchar (90)
    Set @ch =97
    Print @ch

    --The display result is 97, which means that the implicit conversion to a string

  3. DECLARE @ch varchar (90)
    Set @ch =97+ ' a '
    Print @ch

    --The output is: syntax error occurs when converting varchar value ' A ' to a column with a data type of int. Why not first convert the number 97 to a string and then connect to ' a ', is it because 97 was in the front, so SQL Server tried to do it? Let's change the position .

  4. DECLARE @ch varchar (90)
    Set @ch = ' A ' +97
    Print @ch

    --The output is: syntax error occurs when converting varchar value ' A ' to a column with a data type of int. I don't understand why SQL Server always has to convert ' a ' to a number first and cause failure.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.