Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
CREATE FUNCTION example
(
@id int
)
RETURNS @tableout TABLE

begin
 declare @sum float,@lstname nvarchar(50),@fstname nvarchar(50)
 select @sum=sum(marks),@lstname=lastname,@fstname=firstname from student where @id=idstud
 insert into @tableout values (@sum)
end
GO
Posted
Comments
[no name] 7-Sep-12 7:42am    
get rid of @tableout, http://msdn.microsoft.com/en-us/library/ms186755.aspx
Malli_S 7-Sep-12 7:45am    
I think you are missing the table description after

RETURNS @tableout TABLE

statement.

1 solution

try this

SQL
CREATE FUNCTION example
(
@id int
)
RETURNS @tableout TABLE( col1 int)

begin
 declare @sum float,@lstname nvarchar(50),@fstname nvarchar(50)
 select @sum=sum(marks),@lstname=lastname,@fstname=firstname from student where @id=idstud
 insert into @tableout values (@sum)
  return
 end

GO




You forgot to include column in the datatable. ALso after that you have to include return keyword before end.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900