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.
| Author |
Topic |
|
dfarrer
Starting Member
4 Posts |
Posted - 2004-06-11 : 05:45:19
|
| Hello All,Im hoping someone can help me get off the ground with UDF's. I try and create the following in Query Analyser ...USE PUBS -- =============================================-- Create scalar function (FN)-- =============================================CREATE FUNCTION test_function (@p1 int, @p2 int)RETURNS intASBEGIN RETURN @p1 + @p2-- eg.-- DECLARE @sum AS int-- SELECT @sum = @p1 + @P2-- RETURN @sumENDGOAbout the simplest UDF you can make .. it fails with folloing error messages.Server: Msg 170, Level 15, State 1, Line 6Line 6: Incorrect syntax near 'FUNCTION'.Server: Msg 137, Level 15, State 1, Line 12Must declare the variable '@p1'.Any help would be really appreciated.Many ThanksDax Farrer |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-11 : 05:50:04
|
| add a GO statement after use pubs.--****************************************USE PUBS go-- =============================================-- Create scalar function (FN)-- =============================================CREATE FUNCTION test_function (@p1 int, @p2 int)RETURNS intASBEGINRETURN @p1 + @p2-- eg.-- DECLARE @sum AS int-- SELECT @sum = @p1 + @P2-- RETURN @sumENDGOcreate function must always be the first statement in a batch.Duane. |
 |
|
|
JasonGoff
Posting Yak Master
158 Posts |
Posted - 2004-06-11 : 05:51:48
|
| Which version of SQL Server are you using? The code above worked fine on my implementation of SQL2000. |
 |
|
|
dfarrer
Starting Member
4 Posts |
Posted - 2004-06-11 : 05:51:55
|
| Nixce idea, but it didnt work.. still returning same error messages when I try and parse it |
 |
|
|
dfarrer
Starting Member
4 Posts |
Posted - 2004-06-11 : 05:53:29
|
| In the Query Analyser About box its Version 8.00.194 |
 |
|
|
JasonGoff
Posting Yak Master
158 Posts |
Posted - 2004-06-11 : 05:59:39
|
| ok, in query analyser, run..select @@versionWhat server version does that report. If it's 2000, great. Anything else doesn't support functions ! |
 |
|
|
dfarrer
Starting Member
4 Posts |
Posted - 2004-06-11 : 06:03:13
|
| Many thanks, though my Enterprise Manager seems to be 2000 the analyser returns 7. This computer did have 7 installed on it |
 |
|
|
|
|
|
|
|