table-valued functions

Writing SQL stored procedures often requires calling some functions to make the processing process more reasonable and to make functions more reusable. However, when writing SQL functions, you may find that some functions are written under table-valued functions and some are written under table-valued functions. The difference is that table-valued functions can only return one table, and scalar-valued functions can return base types.
1. Create the function
IF EXISTS ( SELECT 1 FROM SYSOBJECTS WHERE NAME = 'uf_getTableA')
DROP FUNCTION uf_getTableA
GO

/*************************** **************************************************** ************************
%% Name: uf_getTableA
%%
%% Parameters: None
%%
%% Return: Valid XX Rule Table
%%
%% Description: Returns a valid XX rule
%%
**************************************** **************************************************** *************
%% Write: faith 2013.05.09
%%
******************************************************************************************************/
CREATE FUNCTION [dbo].[uf_getTableA]()
RETURNS TABLE
AS
RETURN
(
SELECT *
from TableA d
where d.is_valid='T'
and d.start_time<=GETDATE()
and d.end_time>=GETDATE()
and d.verify_stat='1'
)
GO
2.在存储过程中调用
SELECT d.name from uf_getTableA() d order by d.level desc

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326988012&siteId=291194637