如何在存储过程中编写函数 [英] how to write function in store procedure
本文介绍了如何在存储过程中编写函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何编写在存储过程中选择一个值(如userid)的功能....
how to write function of selecting one value like userid in store procedure....
推荐答案
请参考:
如何:创建存储过程和用户定义的函数 [ ^ ]
创建功能(Transact-SQL) [创建功能 [用户定义的函数 [在SQL中创建用户定义的函数 [在SQL Server中使用表值函数 [ ^ ]
SQL Server 2005/2008中最常用的功能 [ ^ ]
编写子函数或另一个存储过程中的过程-SQL Server [
Please refer:
How to: Create Stored Procedures and User-Defined Functions [^]
CREATE FUNCTION (Transact-SQL)[^]
CREATE FUNCTION[^]
User Defined Functions[^]
Creating a User Defined Function in SQL[^]
Some more links for reference:
Using Table-Valued Functions in SQL Server[^]
Most Commonly Used Functions in SQL Server 2005/2008[^]
Write a sub function or procedure inside another stored procedure - SQL Server[^]
就像您可以通过从存储过程中调用函数来选择值一样
like that you can select value by calling function from stored procedure
ALTER PROC [dbo].[USP_StoreProcedureName]
(
@UserId int=0
)
AS
BEGIN
select dbo.Fun_FunctionName(@UserId)
end
--- function description
ALTER Function [dbo].[Fun_FunctionName]
(
@UserId int=0
)
Returns varchar(50)
AS
Begin
DECLARE @ReturnValue VARCHAR(20)
--now set this variable as you like
set @ReturnValue ---- your logic
return @ReturnValue
end
您是真正的意思是函数还是只是在存储过程中选择某些东西.
最简单的方法是只执行查询,例如:
Do you really mean a function or just how to select something in a stored procedure.
The simplest way is to just execute the query, like:
CREATE PROCEDURE abc
AS BEGIN
SELECT ... FROM TheTable WHERE ...;
END;
请参考创建过程 [
Refer to CREATE PROCEDURE [^]
这篇关于如何在存储过程中编写函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文