5-sql Server 2008 Arithmetic, comparison operations, logical operations, and character join operations

Source: Internet
Author: User
Tags arithmetic

Arithmetic as follows:

--Subtraction (+ 、-、 *, \,%) take the remainder operationSELECT--addition Operation3+5  asAddition result 1,3.5+6  asaddition result 2,--Subtraction OperationsTen-2.5  asSubtraction Results 1,15.5+5.5  asSubtraction Results 2,--Multiplication Operations5*3  asMultiplication result 1,1.5*2  asmultiplication result 2,--Division Operation -/6  asDivision result 1, **3.5  asDivision result 2,--take the remainder operation9%4  asThe result of the remainder is 1,Ten%5  asResidual results 2GO

Results:

Comparison operation:

--Comparisons (>, <, >=, <=, =, <>) operations--Greater thanIF 5>3 SELECT '5 greater than 3'  ELSE SELECT '5 less than or equal to 3' --less thanIF 5<3 SELECT '5 less than 3' ELSE SELECT '5 is greater than or equal to 3'--equalsIF 5=3 SELECT '5 equals 3 .' ELSE SELECT '5 is not equal to 3' --greater than or equal toIF 5>=3 SELECT '5 is greater than or equal to 3' ELSE SELECT '5 less than 3'--less than or equal toIF 5<=3 SELECT '5 less than or equal to 3' ELSE SELECT '5 greater than 3'--Not equal toIF 5<>3 SELECT '5 is not equal to 3' ELSE SELECT '5 equals 3 .'

Results:

Logical operation:

--logical (and, or, not) operations IF(Ten > 3  and 2<=1 OR  not Ten> One)--priority order: not, and, orSELECT 'TRUE'ELSESELECT 'FALSE'

Results:

Character Join operations:

--character join (+) operationDECLARE @s1 varchar(Ten)SET @s1 = 'ABC'SELECT @s1+'123'DECLARE @s2 varchar(Ten)SET @s2 = 'ABC'--the right side is a number that must be converted and reconnected .SELECT @s2+CONVERT(varchar(Ten),123)

Results:

5-sql Server 2008 Arithmetic, comparison operations, logical operations, and character join operations

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.