I have this procedure
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
It returns a list correctly except I would also like to run a query on the list that is returned and as far as I am aware I cannot write a query such as
Select * from GetHerdByUserProc 80
So I am looking the best way to convert this to a table-valued query.
I have changed the alter to say 'Create Function x(@user int) Returns Table As'
But that does not seam to work it starts screaming errors at me.
Any ideas? The Database Server is MSSQL2008