Home  >  Article  >  Database  >  sqlserver 存储过程和自定义函数

sqlserver 存储过程和自定义函数

WBOY
WBOYOriginal
2016-06-07 15:07:131456browse

sqlserver 存储 过程 create procedure proc_menu ?@menuId varchar(50), ?@menuTotal int output as begin ?? set nocount on; ?? select @menuTotal=count(*) from dbo.Lov_menu t where t.menu_id=@menuId; end sqlserver 自 定义 函数 create function S

sqlserver 存储过程

create procedure proc_menu
?@menuId varchar(50),
?@menuTotal int output
as
begin
?? set nocount on;
?? select @menuTotal=count(*) from dbo.Lov_menu t where t.menu_id=@menuId;
end

sqlserver 自定义函数

create function Sector_Name(@sctId varchar(10))
returns varchar(50)
as
begin
declare @ccode varchar(50)
declare @name? varchar(50)
declare @pid?? varchar(10)
declare @sctpid varchar(10)
declare @spid?? varchar(10)

select @pid=SCT_PID? from SECTOR where SCT_ID=@sctId
if(@pid=1)
?? set @ccode=(select SCT_NAM from SECTOR where SCT_ID=@sctId)
else if(@pid=0)
?? set @ccode=(select SCT_NAM from SECTOR where SCT_ID=@sctId)
else
begin
?? select @name? =SCT_NAM? from SECTOR where SCT_ID=@sctId
?? select @sctpid=SCT_PID? from SECTOR where SCT_ID=@pid
?? if (@sctpid=1)
? set @ccode =(select SCT_NAM? from SECTOR where SCT_ID = @pid )+'-'+@name
?? else
??? begin
??? while @sctpid 1
?? begin
??? select @spid=SCT_PID? from SECTOR where SCT_ID = @sctpid
??? set @ccode =(select SCT_NAM? from SECTOR where SCT_ID = @sctpid )+'-'+@name
??? set @sctpid=@spid
??? if @sctpid=1
????break
?? end?
?end
end
return @ccode
end

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn