一.函数
函数调用格式:
select 表名.该表中创建的函数
1.系统函数
系统中自带的函数,比如聚合函数(sum等等)
2.自定义函数
(1).标量值函数(只返回单个值)
举例:我们创建了一个Student学生表,现在要求写出一个函数求出其中所有学生的分数总和
create function GetScore() 
returns score 
as 
begin declare @AllScore int  select @AllScore = (select SUM(Score) from Student) return @AllScore 
end --调用函数
select mydatabase.GetScore(2).表值函数(返回查询结果)
举例:在Student学生表中,目前对函数的要求是通过传入学生编号返回学生姓名
create function GetName(@id int) 
returns varchar(30) 
as 
begin declare @name varchar(30) select @name = (select Name from Student where StudentId = @id) return @name 
end--调用函数
select mydatabase.GetName(1)