set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[TelBookFun] ( @OwnerUserID int ) RETURNS TABLE AS RETURN SELECT TelBook.ID, TelBook.Name, TelBook.Address, TelBook.Comment, TelNumbers.TelNo, TelTypes.TelTypes, TelNumbers.TelNoType AS TelTypeId, TelNumbers.SysCode FROM TelTypes INNER JOIN TelNumbers ON TelTypes.FK = TelNumbers.TelNoType RIGHT OUTER JOIN TelBook ON TelNumbers.TelBookID = TelBook.ID WHERE (TelBook.OwnerUserID = @OwnerUserID) OR (TelBook.OwnerUserID = 0)