for a table valued function in sql why cant we write sql statements inside begin and end tags like-
create function dbo.emptable()
returns Table
as
BEGIN --it throws an error
return (select id, name, salary from employee)
END
go
while in scalar valued function we can use these tags like
create function dbo.countemp()
returns int
as
begin
return (select count(*) from employee)
end
go
is there any specific rule where we should use BEGIN & END tags
From the above, I guess
BEGINandENDdenotes the intent/use of multiple statements & hence it requires the table variable to be defined as shown in the code above.from http://www.sqlteam.com/article/intro-to-user-defined-functions-updated