472,334 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

Impossible to use a scalar UDF to pass a parameter to another UDF?

Hello there!

I am working with MS SQL Server 2000.

I have a table function that takes an integer parameter and returns a
table, and I can successfully use it like this (passing a literal
as a parameter):

SELECT * FROM MyTableFunction(1)

or like this (passing a variable as a parameter):

DECLARE @i AS int
SELECT @i = 10
...
SELECT * FROM MyTableFunction(@i)

Now, if I have another function -- a scalar function that returns an
integer, I cannot find a way to use it to specify the parameter value
for the first function. For example, when I write

SELECT * FROM MyTableFunction( dbo.MyScalarFunction() )

SQL Server issues the following complaint:

Incorrect syntax near '.'.

I am really perplexed: what I am doing wrong?

Interestingly, if I re-write the second snippet as

DECLARE @i AS int
SELECT @i = dbo.MyScalarFunction()
...
SELECT * FROM MyTableFunction(@i)

everything works just fine; however, this trick cannot be used as a
workaround because I need to pass result of one function as a parameter
to another inside a view's code -- I cannot declare variables and write
any procedural code...

Any ideas, especially workarounds, would be greatly appreciated.

Thank you,
Yarik.

Jul 23 '05 #1
2 2349

"Yarik" <ya***@garlic.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
Hello there!

I am working with MS SQL Server 2000.

I have a table function that takes an integer parameter and returns a
table, and I can successfully use it like this (passing a literal
as a parameter):

SELECT * FROM MyTableFunction(1)

or like this (passing a variable as a parameter):

DECLARE @i AS int
SELECT @i = 10
...
SELECT * FROM MyTableFunction(@i)

Now, if I have another function -- a scalar function that returns an
integer, I cannot find a way to use it to specify the parameter value
for the first function. For example, when I write

SELECT * FROM MyTableFunction( dbo.MyScalarFunction() )

SQL Server issues the following complaint:

Incorrect syntax near '.'.

I am really perplexed: what I am doing wrong?

Interestingly, if I re-write the second snippet as

DECLARE @i AS int
SELECT @i = dbo.MyScalarFunction()
...
SELECT * FROM MyTableFunction(@i)

everything works just fine; however, this trick cannot be used as a
workaround because I need to pass result of one function as a parameter
to another inside a view's code -- I cannot declare variables and write
any procedural code...

Any ideas, especially workarounds, would be greatly appreciated.

Thank you,
Yarik.


It seems that you can't do what you want directly - I guess it's a
limitation/feature of how UDFs were implemented. The most obvious
workarounds (to me) would be to rewrite your view as a function or stored
procedure, if that's possible - you might want to post your function code if
it's not tool complex, to see if someone can suggest an alternative way of
implmenting it.

Simon
Jul 23 '05 #2
Yarik (ya***@garlic.com) writes:
I have a table function that takes an integer parameter and returns a
table, and I can successfully use it like this (passing a literal
as a parameter):

SELECT * FROM MyTableFunction(1)

or like this (passing a variable as a parameter):

DECLARE @i AS int
SELECT @i = 10
...
SELECT * FROM MyTableFunction(@i)

Now, if I have another function -- a scalar function that returns an
integer, I cannot find a way to use it to specify the parameter value
for the first function. For example, when I write

SELECT * FROM MyTableFunction( dbo.MyScalarFunction() )

SQL Server issues the following complaint:

Incorrect syntax near '.'.

I am really perplexed: what I am doing wrong?
Not reading the manual and getting updated on the rules for calling
table functions, I guess. I'm too lazy to do it myself, but you
can probably not pass expression - that's the same as for stored
procedures.
Interestingly, if I re-write the second snippet as

DECLARE @i AS int
SELECT @i = dbo.MyScalarFunction()
...
SELECT * FROM MyTableFunction(@i)

everything works just fine; however, this trick cannot be used as a
workaround because I need to pass result of one function as a parameter
to another inside a view's code -- I cannot declare variables and write
any procedural code...


Not sure I get this, but I don't see the difference. Keep in mind that
you cannot pass a table column as a parameter to a table-valued function.
Think of it for a while and you realize that for each colunm you get a
new table.

Yes, yes, it could still be useful and in SQL 2005 there is actually
a new join operator to permit this. But in SQL2000 you can't.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: roger | last post by:
I'm having difficulties invoking a user defined table function, when passing to it a parameter that is the result of another user defined function....
2
by: Martin MacRobert | last post by:
Hi, I'm trying to make a specialisation of a template function, so that the second parameter accepts scalar types only (int,double,float etc.). ...
3
by: Ken Adeniji | last post by:
Must declare the scalar variable '@FirstName' ContactGridViewWebForm.aspx <aspqlDataSource RunAt="server" ID="SqlDataSourceContact" ...
5
by: deepdata | last post by:
Hi, I am trying to create a function which returns a scalar data. My function tries to insert a row in a table as well. /** CREATE function...
5
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The...
1
by: Rama Jayapal | last post by:
the following is my code can anybody rectify my problem that i get when running my application "Must declare scalar variable @ID" <asp:GridView...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor,...
1
by: Tony M | last post by:
vs 2005 - vb .net - web forms - xp pro Can't figure out why I keep getting the error Must declare the scalar variable "@CheckUser". The error...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.