我有这个程序
ALTER PROCEDURE [dbo].GetHerdByUserProc(@user int)
As
begin
Declare
@GroupId uniqueidentifier,
@UserTrade bit
Set @GroupId = (select tbUser.group_id from tbUser where Userid = @user)
Set @UserTrade = (select tbUser.isTrade from tbUser where Userid = @user)
if @GroupId IS NOT NULL and @UserTrade = '1'
Begin
select HerdId from tbUserHerds where tbUserHerds.UserId in (select Userid from tbUser where tbUser.Group_Id = @GroupId)
return;
END
If @GroupId IS NOT NULL
Begin
select HerdId from tbUserHerds where tbUserHerds.UserId = @user
return;
End
return;
End
它正确返回一个列表,除了我还想在返回的列表上运行一个查询,据我所知,我无法编写查询,例如
Select * from GetHerdByUserProc 80
所以我正在寻找将其转换为表值查询的最佳方法。
我已经改变了说'Create Function x(@user int) Returns Table As'
但这似乎不起作用,它开始向我尖叫错误。
有任何想法吗?数据库服务器是 MSSQL2008