all groups > sql server programming > october 2003 >
You're in the

sql server programming

group:

Newbie: About create multi statement table function


Re: Newbie: About create multi statement table function David Portas
10/17/2003 11:11:21 PM
sql server programming: You didn't INSERT anything into your return table. Your @worktable is
redundant.

CREATE FUNCTION tfunc (@param INTEGER = 0)
RETURNS @tfunc TABLE
(col1 INTEGER,
col2 INTEGER,
col3 INTEGER)
AS
BEGIN
INSERT INTO @tfunc (col1, col2, col3) values (1, 3, 5)
RETURN
END

GO

SELECT * FROM tfunc(1)

Use a view rather than a function wherever possible. A multi-statement
table-valued function is procedural code which will generally perform poorly
compared to set-based queries.

--
David Portas
------------
Please reply only to the newsgroup
--

Newbie: About create multi statement table function Jeff
10/17/2003 11:27:54 PM
Hello

I'm just trying to learn how to program functions in Sqlserver 2000.
and created this function, but it returns no rows, just the column headers
in Query Analyzer

Why doesn't it return any rows?? I thought that the INSERT statement works,
but I'm a newbie

create function tfunc (@param int = 0) returns @tfunc table
(field_1 int,
field_2 int,
field_3 int)
as begin
declare @worktable table (
field_1 int not null,
field_2 int,
field_3 int)

insert @worktable (field_1, field_2, field_3) values (1, 3, 5)
return
end

go
select * from dbo.tfunc(1) --This select returns no rows

Best Regards
Jeff

AddThis Social Bookmark Button