Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 create function not working...

Author  Topic 

daugman
Starting Member

2 Posts

Posted - 2001-11-28 : 09:47:37
When trying to compile ANY function, including the ones found on this site (the user-defined function article) or in BO, I get the following errors :

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'FUNCTION'.
Server: Msg 137, Level 15, State 1, Line 7
Must declare the variable '@Country'.
Server: Msg 178, Level 15, State 1, Line 19
A RETURN statement with a return value cannot be used in this context.

Here is the function I'm trying (right from the article):

CREATE FUNCTION whichContinent
(@Country nvarchar(15))
RETURNS varchar(30)
AS
BEGIN
declare @Return varchar(30)
select @return = case @Country
when 'Argentina' then 'South America'
when 'Belgium' then 'Europe'
when 'Brazil' then 'South America'
when 'Canada' then 'North America'
when 'Denmark' then 'Europe'
when 'Finland' then 'Europe'
when 'France' then 'Europe'
else 'Unknown'
end

return @return
end

Any ideas?

izaltsman
A custom title

1139 Posts

Posted - 2001-11-28 : 09:53:57
Just checking -- are you on SQL7 or SQL2k? User-defined functions were not available on SQL7.

Go to Top of Page
   

- Advertisement -