码迷,mamicode.com
首页 > 数据库 > 详细

Chapter 4.SQL编程

时间:2016-06-14 14:16:34      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

----------------------------------SQL编程---------------------------------
--1、声明变量
--declare @name varchar(50)
--declare @age int

--同时声明多个变量
declare @name varchar(50) , @age int 

--2、为变量赋值
set  @name=lisa  --方式1
select @age=18  --方式2

--3、输出
select 姓名, @name
select 年龄, @age
技术分享
---4、while 循环 declare @i int=1 --声明变量同时赋值 while @i<=100 begin print hello set @i=@i+1 end

--练习:计算1-100之间的所有整数的和 declare @a int=1 declare @sum int=0 while @a<=100 begin set @sum=@sum+@a set @a=@a+1 end print @sum

技术分享
--5、if else语句 declare @n int=3 if @n>10 begin print @n>10 end else if @n>5 and @n<=10 begin print @n>5 and @n<=10 end else begin print@n<=5 end

技术分享
--练习:计算1-100之间所有奇数/偶数的和 declare @sumJishu int=0 declare @j int =1 while @j<=100 begin if @j%2<>0 begin set @sumJishu=@sumJishu+@j end set @j=@j+1 end print @sumJishu
技术分享
declare @sumOushu int=0,@o int=2
while @o<=100
    begin
        set @sumOushu=@sumOushu+@o
        set @o=@o+2
    end
print @sumOushu

技术分享
--continue:跳出本次循环 --break:跳出循环 --全局变量(系统变量) --两个@@ 开头,一般都是系统变量 --注: 系统变量只能查询,不能赋值,不能修改
select @@VERSION

技术分享
select @@ERROR

技术分享
select @@LANGUAGE

  技术分享
select @@SERVERNAME

  技术分享

 

Chapter 4.SQL编程

标签:

原文地址:http://www.cnblogs.com/xiao55/p/5583589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!