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 1: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 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,077
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web02 | 2.8.140814.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