ylbtech_sqlserver
--1、定义三个变量分别保存你的姓名,年龄和身高,然后赋值并且输出 --DECLARE @name varchar(10) , @age int , @height float DECLARE @name varchar(10) DECLARE @age int DECLARE @height float SET @name = '张三' SET @age = 23 SET @height = 1.78 PRINT @name PRINT @age PRINT @height --PRINT @name + ' ' + convert(varchar, @age) + ' ' + convert(varchar,@height) /* cast(数据 as 类型) convert (类型 ,数据) convert(varchar, @age) */ --2、定义变量实现求2个整数的和,平均值 DECLARE @a int DECLARE @b int DECLARE @sum int DECLARE @avg int SET @a = 10 SET @b = 20 SET @sum = @a + @b SET @avg = @sum/2 PRINT @sum PRINT @avg --3、定义2个变量保存2个数值,然后if判断这2个数值是否相等 DECLARE @a int DECLARE @b int SET @a = 10 SET @b = 101 IF @a = @b BEGIN PRINT '相等' END ELSE BEGIN PRINT '不等' END --4、利用循环打印输出1~10这10个整数 DECLARE @i int SET @i = 1 WHILE @i <= 10 BEGIN PRINT @i SET @i = @i + 1 END --5、定义变量保存一个整数,然后利用循环计算并输出这个整数的阶乘 DECLARE @n int DECLARE @i int DECLARE @s int SET @n = 5 SET @i =1 SET @s = 1 WHILE @i <= @n BEGIN SET @s = @s * @i SET @i = @i + 1 END PRINT @s