Hello,
i would like to get the result of a function in a select-statement depending on the result of an other column. I attached a little sample that works on the table syscolumns, so everybody should be able to check by now.
The only thing I get is an error function name not recognized
create Function fn_test( @N bigint)
RETURNS Table
AS
RETURN (
SELECT
@N + id as Result
FROM syscolumns
)
Sample SELECT:
Select typestat, fn_Test( typestat ) FROM syscolumns
Any hint would be very kind
Thanks in advance
Matthias

user defined function in a select
Conversion
I need something like the OUTPUT-parameter in a PROCEDURE, but thats' not possible - or do you know a way
In the original function I expect 6 Values, in a single row therefore I choosed a table as the return value. As I read your answer everything with the error ist clear, but how to get the values from the function - I don't want to use a single Selects for all values because I use them in a report for each Row four times - so I would become 24 new selects and a very long statement with the opportunity for different mistakes.
swtpotato183
thank you for your reply.
I've tested this already, if I do so I get an error (translated from german)
Message no 208
unknown objectname 'dbo.fn_Test'
The functions is shown in the function-section of the Query Analyzer as dbo.fn_Test
SQLServer Developer Edition Version is 8.00.760 (SP3)
on WIN XP
Any other idea
Regards
Matthias
sasa_msh
Select typestat, dbo.fn_Test( typestat ) FROM syscolumns
cpede
Thank you Steve and Blair Allen for your help
Matthias
LTaylor
Prajakta
confirm the function is owned by dbo. . .
run this query:
select u.name+'.'+ f.name
from sysobjects f inner join sysusers u on
f.uid = x.uid
where f.xtype = 'fn'
BarKey
select u.name+'.'+ f.name from sysobjects f inner join sysusers u on f.uid = u.uid where f.xtype = 'if'
and i see the function listed
B Sutton
CREATE TABLE statements, sample data and desired output, my guess is that you could do something like this:
select
T.typestat, F.colA, F.colB, F.colC
from myTable as T
cross apply fn_test(T.typestat)
SK
Nada Ali
The items in the SELECT list must be single-valued. In your example, you are using a table-valued function in the SELECT list. What result do you expect by specifying a table as one of your result columns The reason this doesn't work is because the function is table-valued.
Steve Kass
Drew University