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)
 Executing a UDF

Author  Topic 

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-03-22 : 10:43:28
Hi Gurus,

A Scalar UDF can be invoked as
Select dbo.MySclFunc (7)

In the BOL under Execute --> Transact SQL Ref,
just before the syntax , it says
"To invoke a function, use the Syntax described for EXECUTE stored_procedure"

So it is implying that the function can be "Executed" with a Exec statement as in same as a stored procedure.
Can anybody tell me how to accomplish that (I mean how to make the Statement in BOL a reality).

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-03-23 : 08:07:52
It's as it says, but an example in BOL would've been nice.

declare @x varchar(10)
exec @x = dbo.fnToString 38 --equivalent to: set @x = dbo.fnToString(38)
select @x

Quite why you'd bother doing it this way though, I'm not sure.


Ryan Randall
www.monsoonmalabar.com

Ideas are easy. Choosing between them is the hard part.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-23 : 08:36:48
Also make sure that you should not specify the parameters in braces


declare @x varchar(10)
exec @x = dbo.fnToString(38) -- will give error
select @x

declare @x varchar(10)
set @x = dbo.fnToString(38) -- will not give error
select @x


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-03-23 : 08:50:21
Thanks both of you, for curing my pain.
From both answers I learned 2 ways to use functions.

quote:
Originally posted by RyanRandall


Quite why you'd bother doing it this way though, I'm not sure.



Answer : While working, I'm learning and in the process, I came across with this in BOL. I struggled a while, but couldn't see any way to resolve it, so i decided to put it to you Gurus.

Go to Top of Page

majkinetor
Yak Posting Veteran

55 Posts

Posted - 2006-03-23 : 09:01:53
That is exactly what I am talking about when I say that MS products are badly designed.

VB was full of such bad design isues prior to .NET version.

I mean, having 2 ways to call functions, one with and one without braces in serious application like SQL Server is really nonsense.... Not to count 1000 other places where you can do THIS but only if THAT.

I see why IBM DB2 is so expensive...

www.r-moth.com
Go to Top of Page

jhermiz

3564 Posts

Posted - 2006-03-28 : 11:23:35
quote:
Originally posted by majkinetor

That is exactly what I am talking about when I say that MS products are badly designed.

VB was full of such bad design isues prior to .NET version.

I mean, having 2 ways to call functions, one with and one without braces in serious application like SQL Server is really nonsense.... Not to count 1000 other places where you can do THIS but only if THAT.

I see why IBM DB2 is so expensive...

www.r-moth.com



That is not considered bad design. There are several *ways* to do an operator overload function or a simple arithmaetic expression in C/C++ whether in Windows or Linux. It is not considered bad design. You just don't know how to use the tools effectively so I'd recommend reading the help files that come with the tool.



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-03-28 : 11:43:37
quote:
Originally posted by majkinetor

That is exactly what I am talking about when I say that MS products are badly designed.

VB was full of such bad design isues prior to .NET version.

I mean, having 2 ways to call functions, one with and one without braces in serious application like SQL Server is really nonsense.... Not to count 1000 other places where you can do THIS but only if THAT.

I see why IBM DB2 is so expensive...



What the ... ?????

I guess you are right ... more than 1 way to accomplish something = bad. Only 1 way to accomplish something = bad also. Stupid Microsoft !

Obviously, a good design would provide exactly 15 ways to accomplish things.
Go to Top of Page
   

- Advertisement -