CREATE FUNCTION dbo.GetInfo(@CustomerID int) returns @userTable table -- Defines format of the table to be returned. ( ID int not null, name nvarchar(20) not null ) AS BEGIN DECLARE @ID int, @CName nvarchar(20) SELECT @ID= id, @CName = name from myTable where id=@CustomerID; INSERT @userTable SELECT @ID, @CName; RETURN;-- It cannot have any arguments. Once it is called, returns all rows in table variable END; --Procedure to call it GO
SELECT ID,name from dbo.GetInfo(100); GO
|