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.