views:

212

answers:

1

When trying to create a user-defined functions (UDFs) on sybase 15+, you may get the following error: "illegal built-in function statement in scalar SQL function" This is b/c "non deterministic" functions such as getdate(), rand(), newid() are not allowed in UDFs.

Is there a way around this limitation?

Note that I plan answer my own question here.

A: 

The solution is to create a view such as:

create view vGetDate as select getdate() as gtdt

Then in the UDF select from that view:

create function udf_getdate
returns datetime
as
declare @gd datetime
select @gd=gtdt from vGetDate
return @gd
go

Now call the function:

select dbo.udf_getdate()
mosheb