Click here to Skip to main content
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)

  Print Answers RSS
0 Maciej Los 424
1 ridoy 400
2 DamithSL 230
3 OriginalGriff 179
4 Suvendu Shekhar Giri 150
0 OriginalGriff 8,033
1 DamithSL 6,179
2 Sergey Alexandrovich Kryukov 5,538
3 Maciej Los 5,508
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2014
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