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