Problem creating a function by code

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
vdev
Posts: 17
Joined: Tue 15 Sep 2009 08:28

Problem creating a function by code

Post by vdev » Wed 07 Dec 2011 15:54

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

AndreyZ

Post by AndreyZ » Wed 07 Dec 2011 17:44

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.

Post Reply