Server
Create user-defined functions that are free to be used directly in a transaction SQL, like a system function in your query statement
Direct use.
CREATE FUNCTION
Grammar
CREATE FUNCTION [owner_name.] Function_name
([{@parameter_name [as] scalar_parameter_data_type [= default]} [,... N]])
--Create a function
Create function GetValue ()
returns int
As
Begin
Return (select CONVERT (int,value) as Value from test where [name]= ' test ')
End
Go
SELECT * from Test2 where Value=dbo.getvalue ()
Go
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 on T3. Jid=t3. JID where T1. date>= @t1 and T1. date< @t2)
Go
SELECT * from Dbo.gettabletest (' 1999/1/1 ', ' 2001/2/1 ')
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.