sql:function

--查询权限函数
--1
declare @names varchar(3000)
set @names=‘‘
select @names=@names+isnull(AdminPermissFormName,‘‘)+‘ , ‘ from BookAdminPermissTypeList  where AdminPermissTypeID in(8,9,10)
set @names=left(@names,len(@names)-1)
print @names
select  @names

--2
declare @sql nvarchar(4000),@where nvarchar(1000)
set @sql=‘‘
set @where=‘8,9,10‘
set @sql=@sql+‘declare  @names varchar(3000)‘
set @sql=@sql+‘ set @names=‘‘‘‘‘
set @sql=@sql+‘ select @names =@names +isnull(AdminPermissFormName,‘‘‘‘)+‘‘ , ‘‘  from BookAdminPermissTypeList  where AdminPermissTypeID in(‘+@where+‘)‘
set @sql=@sql+‘ set @names=left(@names,len(@names)-1)‘
set @sql=@sql+‘ select @names‘
print @sql
--exec (@sql)
exec sp_executesql @sql


--不可以用
if exists(select 1 from sysobjects where name = ‘f_GetAdminPermissFormFullName‘ and xtype = ‘FN‘) 
drop function f_GetAdminPermissFormFullName 
go 
CREATE function f_GetAdminPermissFormFullName
(
	@AdminPermissTypeID nvarchar(1000)
)
returns nvarchar(1000)
as
begin
declare @sql nvarchar(4000),@re nvarchar(1000)
set @sql=‘‘
--set @where=‘8,9,10‘
set @sql=@sql+‘declare  @names varchar(3000)‘
set @sql=@sql+‘ set @names=‘‘‘‘‘
set @sql=@sql+‘ select @names =@names +isnull(AdminPermissFormName,‘‘‘‘)+‘‘ , ‘‘  from BookAdminPermissTypeList  where AdminPermissTypeID in(‘+@AdminPermissTypeID+‘)‘
set @sql=@sql+‘ set @names=left(@names,len(@names)-1)‘
set @sql=@sql+‘ return @names‘
return exec(@sql)
end
go

 

sql:function,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。