<!--打赏 End-->

循环 游标

declare @i int,@t int
set @t=0;
set @i=2;
while @i<=10
begin 
 set @t=@t+@i;
 set @i=@i+2;
end
print @t

begin
 waitfor time'8:00'
 execute sp_addrole 'manager'
end
break continue return 
View Code
declare @ch int;
set @ch=92;
select char(@ch+5)

select abs(-5),replace('abcdef','cd','SS'),substring('中国人民',3,2),ASCII('sql')
select abs(0.0),abs(6.0),round(123.456,2),round(123.456,-2),rand(),rand(6)
select left('山东职业学院',2),right('山东职业学院',3),substring('山东职业学院',3,2)
select ascii('A'),CHAR(65)
select str(5.392754,6,3),str(-7.566,4,2)
View Code
select getdate(),year(getdate()),month(getdate()),day(getdate())

select 学号,sex=
 case 性别 
 when '' then '男生'
 when '' then '女生'
 end
 from stu

 declare @ss char(14);
 set @ss='数据结构'
 select cast(@ss as char(4)), convert(char(4),@ss)
View Code
create function average(@num int)
returns int
as 
begin 
declare @aver int
select @aver =avg(age) from xscj where id=@num 
return @aver
end
drop function average

use test 
go
declare @num int,@res int;
set @num=10;
--select @res=dbo.average(@num)
exec @res=dbo.average @num= @num
print @res


create table xscj(
id int not null identity(1,1) primary key,
age int
)

declare @i int;
set @i=1;
while @i<=20
begin 
 insert xscj values(@i);
 set @i=@i+1;
end 
View Code

 

posted @ 2017-11-27 23:59  mikefts  阅读(105)  评论(0编辑  收藏  举报