SQLSERVER2000新增功能介绍1

2008-04-02 10:39:17来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

建立用户自定义函数,能够自由的在一个Transaction SQL 中直接使用,就像一个系统函数相同在您的查询语句中
直接使用。
CREATE FUNCTION
语法
CREATE FUNCTION [ owner_name. ] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] ) www.chinai tp ow er.com采集不要钱NM7K5

RETURNS scalar_return_data_typewww.chinai tp ow er.com采集不要钱NM7K5

[ WITH < function_option> [ [,] ...n] ] www.chinai tp ow er.com采集不要钱NM7K5

[ AS ]www.chinai tp ow er.com采集不要钱NM7K5

BEGIN
function_body
RETURN scalar_expression
ENDwww.chinai tp ow er.com采集不要钱NM7K5

Inline Table-valued Functionswww.chinai tp ow er.com采集不要钱NM7K5

CREATE FUNCTION [ owner_name. ] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] ) www.chinai tp ow er.com采集不要钱NM7K5

RETURNS TABLE www.chinai tp ow er.com采集不要钱NM7K5

[ WITH < function_option > [ [,] ...n ] ] www.chinai tp ow er.com采集不要钱NM7K5

[ AS ] www.chinai tp ow er.com采集不要钱NM7K5

RETURN [ ( ] select-stmt [ ) ] www.chinai tp ow er.com采集不要钱NM7K5

Multi-statement Table-valued Functionswww.chinai tp ow er.com采集不要钱NM7K5

CREATE FUNCTION [ owner_name. ] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] ) www.chinai tp ow er.com采集不要钱NM7K5

RETURNS @return_variable TABLE < table_type_definition > www.chinai tp ow er.com采集不要钱NM7K5

[ WITH < function_option > [ [,] ...n ] ] www.chinai tp ow er.com采集不要钱NM7K5

[ AS ] www.chinai tp ow er.com采集不要钱NM7K5

BEGIN
function_body
RETURN
ENDwww.chinai tp ow er.com采集不要钱NM7K5

< function_option > ::=
{ ENCRYPTION | SCHEMABINDING }www.chinai tp ow er.com采集不要钱NM7K5

< table_type_definition > :: =
( { column_definition | table_constraint } [ ,...n ] ) www.chinai tp ow er.com采集不要钱NM7K5

示例www.chinai tp ow er.com采集不要钱NM7K5


--创建函数
create function getValue()
returns int
as
begin
return (select convert(int,Value) AS Value from Test where [Name]='Test')
end
gowww.chinai tp ow er.com采集不要钱NM7K5

select * from Test2 where Value=dbo.getValue()www.chinai tp ow er.com采集不要钱NM7K5

gowww.chinai tp ow er.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.chinai tp ow er.com采集不要钱NM7K5

gowww.chinai tp ow er.com采集不要钱NM7K5

select * from dbo.getTabletest('1999/1/1','2001/2/1')www.chinai tp ow er.com采集不要钱NM7K5

www.chinai tp ow er.com采集不要钱NM7K5

www.chinai tp ow er.com采集不要钱NM7K5

www.chinai tp ow er.com采集不要钱NM7K5


标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: SQL查询语句使用

下一篇: SQLServer性能分析参数