I'm really a beginner in SQL Server programming. I'm writing a table-valued user defined function but when i execute it I get this errors:
*Msg 178, Level 15, State 1, Procedure Select_info_FN, Line 10
A RETURN statement with a return value cannot be used in this context.
Msg 102, Level 15, State 31, Procedure Select_info_FN, Line 12
Incorrect syntax near 'BEGIN'.*
Here's my code :
create function Select_info_FN() returns table
as
begin
declare @count int
SELECT @count = COUNT(*) FROM dbo.info
if @count = 0
begin
INSERT INTO dbo.info VALUES (NULL, NULL, NULL, NULL, NULL)
end
return (SELECT * FROM dbo.info)
end
INSERTin a function anyway, so even if you correct the other part of the syntax I don't think you're going to get too far...INSERTin a table-valued function it it's an insert into the result table, but it's true that you can't perform an insert into a table that exists in the database.