Click here to Skip to main content
11,435,451 members (58,526 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
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 7-Sep-12 2:32am
Comments
Wes Aday at 7-Sep-12 7:42am
   
get rid of @tableout, http://msdn.microsoft.com/en-us/library/ms186755.aspx
Malli_S at 7-Sep-12 7:45am
   
I think you are missing the table description after

RETURNS @tableout TABLE

statement.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this

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.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100