Click here to Skip to main content
12,455,442 members (57,574 online)
Rate this:
 
Please Sign up or sign in to vote.
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 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

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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2016
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