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
 Transact-SQL (2000)
 Can't create function by Analyzer

Author  Topic 

hornet
Yak Posting Veteran

96 Posts

Posted - 2006-09-22 : 03:12:41
Hi all!
I'm trying to execute next statement, but
can't
exec sp_executesql
N'exec sp_executesql @P1', N'@P1 nvarchar(208)',
N' IF EXISTS (SELECT * FROM sysobjects WHERE name = ''fGetTableCodeArchivePrices'')
BEGIN
CREATE FUNCTION fGetTableCodeArchivePrices()
RETURNS INT AS
BEGIN
RETURN 39
END
END'

SQL is returning next messages:
Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'FUNCTION'.
Server: Msg 178, Level 15, State 1, Line 7
A RETURN statement with a return value cannot be used in this context.
Thanks!

LazyDragon
Starting Member

30 Posts

Posted - 2006-09-22 : 03:20:07
Why you have to create the function using Dynamic SQL?


LazyDragon
Go to Top of Page

hornet
Yak Posting Veteran

96 Posts

Posted - 2006-09-22 : 03:28:05
I have to write a programm which will be to update the Database.
So I run this script from programm via the class which works with Database. e.g. next script is working normally:
IF NOT EXISTS (SELECT * from sysobjects where name = 'CountNumber' ) BEGIN CREATE TABLE [CountNumber] ([CountNumber] [int] NOT NULL, CONSTRAINT [PK_CountNumber] PRIMARY KEY CLUSTERED ([CountNumber]) ON [PRIMARY]) ON [PRIMARY] INSERT INTO CountNumber (CountNumber) values (0) END
Go to Top of Page
   

- Advertisement -