I'm working on a local and a remote SQL Server instance with SSMS. I create a tiny function like:
create function ufnTestFunc ()
returns int
begin
return 1
end
When I try to 'modify' it, or choose 'script function as -> alter', I get an error like:
Script failed for UserDefinedFunction 'dbo.ufnTestFunc'. (Microsoft.SqlServer.Smo)
- Syntax error in TextHeader of UserDefinedFunction 'ufnTestFunc'. (Microsoft.SqlServer.Smo)
This also happens on already existing functions. What may be the reason?
Notes:
Local Server:
Microsoft SQL Server Express Edition (64-bit) - 10.50.2500.0
Remote Server:
Microsoft SQL Server Web Edition (64-bit) - 10.50.1600.1
SSMS:
Microsoft SQL Server Management Studio 10.50.2500.0
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 6.0
Microsoft .NET Framework 2.0.50727.5448
Run sp_helptext N'ufnTestFunc'
Is there anything in the "comment" section above the function that looks odd?
Embedded comments /* */ can sometimes cause that error.
Example:
/*
This function does something.
/* NOTE: not any useful, though */
More stuff...
*/
alter function ufnTestFunc ()
returns int
begin
return 1
end
Ok like someone mentioned before, but with a little difference.
The problem is the AS keyword. Although the AS keyword before the function content is optional, SSMS can't handle functions without it. They work, but make trouble. It's a bug and not mentioned anywhere in the BOL.
I normally use the AS keyword, but this time the DB is from a previous coder, who didn't use it. In my test function I also didn't use it to make the function as small as possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With