SQL Tech Insider-Comparison of 7 varchar types of numbers and numbers of type int +cast applicable

Source: Internet
Author: User

DECLARE @x varchar (ten);D eclare @y int;declare @z VARCHAR (10); SET @x =  ' 1000 '; SET @y =  ' 2000 '; SET @z = ' +3000 ';

-The first Kind

SELECT case when  @x < @y Then ' true ' Else ' FALSE ' END as [x<y?] If case is  @y < @z Then ' true ' else ' fals E ' End as [y<z?], case is   @x < @z Then ' TRUE ' ELSE ' FALSE ' END as [x<z?]

Result is

X<y? Y<z? X<z?
Truetruefalse

The second Kind

SELECT case when  @x < @y Then ' true ' Else ' FALSE ' END as [CAST (x) <y?] If case is  @y < @z Then ' true ' else  ' False ' end as [Y<cast (z)], case is   @x < @z Then ' TRUE ' ELSE ' false ' end as [x<z?] and Case is  CAST (@x As int) < CAST (@z as int) then       ' TRUE ' ELSE ' FALSE ' END as [CAST (x) <cast (z)?]

Result is

CAST (x) <y? Y<cast (z)? X<z? CAST (x) <cast (z)?
Truetruefalsetrue

SQL Tech Insider-Comparison of 7 varchar types of numbers and numbers of type int +cast applicable

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.