SQLSERVER2000新增功效介绍1[MSSQL防范]
本文“SQLSERVER2000新增功效介绍1[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
成立用户自定义函数,可以安闲的在一个Transaction SQL 中直接利用,就像一个系统函数一样在你的查询语句中
直接利用.
CREATE FUNCTION
语法
CREATE FUNCTION [ owner_name. ] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] ) www.iTbulo.com-NM7K5
RETURNS scalar_return_data_typewww.iTbulo.com-NM7K5
[ WITH < function_option> [ [,] ...n] ] www.iTbulo.com-NM7K5
[ AS ]www.iTbulo.com-NM7K5
BEGIN
function_body
RETURN scalar_expression
ENDwww.iTbulo.com-NM7K5
Inline Table-valued Functionswww.iTbulo.com-NM7K5
CREATE FUNCTION [ owner_name. ] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] ) www.iTbulo.com-NM7K5
RETURNS TABLE www.iTbulo.com-NM7K5
[ WITH < function_option > [ [,] ...n ] ] www.iTbulo.com-NM7K5
[ AS ] www.iTbulo.com-NM7K5
RETURN [ ( ] select-stmt [ ) ] www.iTbulo.com-NM7K5
Multi-statement Table-valued Functionswww.iTbulo.com-NM7K5
CREATE FUNCTION [ owner_name. ] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] ) www.iTbulo.com-NM7K5
RETURNS @return_variable TABLE < table_type_definition > www.iTbulo.com-NM7K5
[ WITH < function_option > [ [,] ...n ] ] www.iTbulo.com-NM7K5
[ AS ] www.iTbulo.com-NM7K5
BEGIN
function_body
RETURN
ENDwww.iTbulo.com-NM7K5
< function_option > ::=
{ ENCRYPTION | SCHEMABINDING }www.iTbulo.com-NM7K5
< table_type_definition > :: =
( { column_definition | table_constraint } [ ,...n ] ) www.iTbulo.com-NM7K5
示例www.iTbulo.com-NM7K5
--成立函数
create function getValue()
returns int
as
begin
return (select convert(int,Value) AS Value from Test where [Name]='Test')
end
gowww.iTbulo.com-NM7K5
select * from Test2 where Value=dbo.getValue()www.iTbulo.com-NM7K5
gowww.iTbulo.com-NM7K5
create function getTabletest(@t1 datetime,@t2 datetime)
returns table
as
return( select t1.Field1 ,t2.Field1,t2.Qty,t3.Field1,t3.Field1
from Table1 t1 inner join Table2 t2 on t1.ID=t2.ID inner join Table3 t3 on t2.JID=t3.JID where t1.Date>=@t1 and t1.Date<@t2)www.iTbulo.com-NM7K5
gowww.iTbulo.com-NM7K5
select * from dbo.getTabletest('1999/1/1','2001/2/1')www.iTbulo.com-NM7K5
www.iTbulo.com-NM7K5
www.iTbulo.com-NM7K5
www.iTbulo.com-NM7K5
以上是“SQLSERVER2000新增功效介绍1[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:本文地址: | 与您的QQ/BBS好友分享! |