Page 1 of 1

Problem creating a function by code

Posted: Wed 07 Dec 2011 15:54
by vdev
Hi, I am trying to create a function in the database by code.

For example..

create function dbo.myfunction(@i int)
returns int
as
begin
declare @r int
set @r = @i * 2
return @i
end


I get the message a RETURN statement with a return value cannot be used in this context. Must declare the scalar variable @id.

Incorrect syntax near the keyword 'function'.


This works from management studio but fails from tmsscript, tmsconnection

Posted: Wed 07 Dec 2011 17:44
by AndreyZ
Hello,

I have executed the following code:

Code: Select all

MSScript.SQL.Clear;
MSScript.SQL.Add('create function dbo.myfunction(@i int)');
MSScript.SQL.Add('returns int');
MSScript.SQL.Add('as');
MSScript.SQL.Add('begin');
MSScript.SQL.Add('declare @r int');
MSScript.SQL.Add('set @r = @i * 2');
MSScript.SQL.Add('return @i');
MSScript.SQL.Add('end');
MSScript.Execute;
, and there were no problems. Please check if this code works for you. If it doesn't work, please try using the latest SDAC version 6.1.3 and check if the problem persists.