Sqlserver存储过程返回表,如何实现?
CreateProcedureCS_GR_AlloDays@LeaveTypeIdint,@UserNamenvarchar(50)Asdeclare@strWherev...
Create Procedure CS_GR_AlloDays
@LeaveTypeId int,
@UserName nvarchar(50)
As
declare @strWhere varchar(100);--查询条件,模糊查询
declare @strcmd varchar(1500);
if(@UserName is null) --全部查询
set @strWhere=''
else
set @strWhere='where E.LoginName like %'+@UserName+'%'
set @strcmd=' select F.LeaveItem,E.*,F.DefaultDay,E.DaysUsed from('+
'select LoginName,DaysUsed'+
'from Right_Users A'+
'Inner join('+
' select proposerID ,sum(LeaveDay) as DaysUsed from LM_Leave '+
' where LeaveTypeId='+@LeaveTypeId+' and LeaveStatusID=0 group by proposerID'+
') B on B.ProposerId=A.UsersID )E'+
'left join LM_LeaveType F on F.LeaveTypeId='+@LeaveTypeId+@strWhere
exec(@strcmd)
--------------
传参数执行以后 返回这个:
USE [AMK_GRP_Dev]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[CS_GR_AlloDays]
@LeaveTypeId = 1
SELECT 'Return Value' = @return_value
GO
---------
返回 'Return Value'=null.
请问如何返回我想要的表? 展开
@LeaveTypeId int,
@UserName nvarchar(50)
As
declare @strWhere varchar(100);--查询条件,模糊查询
declare @strcmd varchar(1500);
if(@UserName is null) --全部查询
set @strWhere=''
else
set @strWhere='where E.LoginName like %'+@UserName+'%'
set @strcmd=' select F.LeaveItem,E.*,F.DefaultDay,E.DaysUsed from('+
'select LoginName,DaysUsed'+
'from Right_Users A'+
'Inner join('+
' select proposerID ,sum(LeaveDay) as DaysUsed from LM_Leave '+
' where LeaveTypeId='+@LeaveTypeId+' and LeaveStatusID=0 group by proposerID'+
') B on B.ProposerId=A.UsersID )E'+
'left join LM_LeaveType F on F.LeaveTypeId='+@LeaveTypeId+@strWhere
exec(@strcmd)
--------------
传参数执行以后 返回这个:
USE [AMK_GRP_Dev]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[CS_GR_AlloDays]
@LeaveTypeId = 1
SELECT 'Return Value' = @return_value
GO
---------
返回 'Return Value'=null.
请问如何返回我想要的表? 展开
2个回答
2015-07-14 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464984
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
代码参考如下:
create proc p_abc @i int
as
--中间有个非常复杂的计算
select * from #tmp where fid=@i
go
create proc p_test @i int
as
set nocount on
create table #temp(.....)
insert into #temp
exec p_abc @i --执行这个语句后返回一个table,把这个返回结果插入到临时表
go
create proc p_abc @i int
as
--中间有个非常复杂的计算
select * from #tmp where fid=@i
go
create proc p_test @i int
as
set nocount on
create table #temp(.....)
insert into #temp
exec p_abc @i --执行这个语句后返回一个table,把这个返回结果插入到临时表
go
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询