Monday, March 19, 2012

Calling a UDF from ADO

Can you call a User-defined Function directly from ADO or ADO.NET or do you
have to wrap it in a stored procedure. I would test this but can't right now
- sorry.
thanksselect dbo.MyFunction('blah') as hello
Call like any other sql query in ADO.
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net
"brian" <brian@.discussions.microsoft.com> wrote in message
news:70389B03-B9D1-43E5-96EA-219BF0C53632@.microsoft.com...
> Can you call a User-defined Function directly from ADO or ADO.NET or do
> you
> have to wrap it in a stored procedure. I would test this but can't right
> now
> - sorry.
> thanks|||"brian" wrote:

> Can you call a User-defined Function directly from ADO or ADO.NET or do
> you
> have to wrap it in a stored procedure. I would test this but can't right
> now
> - sorry.
> thanks
You can execute a UDF and get the results back with any library that can
execute a texual command: for example, given these two functions...
create function scalar_func() returns int as begin
return 5
end
go
create function tab_func() returns table as
return (
select * from some_madeup_table
)
go
...You can (using ADO with VB 6)...
Set SomeRS = SomeConn.Execute("select dbo.scalar_func() as 'some_col'")
Set SomeRS = SomeConn.Execute("select * from dbo.tab_func()")
Craig

No comments:

Post a Comment