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
 SQL Server Development (2000)
 user defined function

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-22 : 10:17:06
Chris writes "Hi,

I'm trying to call a UDF like this:
#################
SELECT a.PO_NUMBER, a.PO_DATE, a.GL_CODE, (SELECT dept FROM dbo.udfTEST (a.PO_NUMBER, a.GL_CODE)) AS Dept
FROM Table1 a
GROUP BY a.PO_NUMBER, a.PO_DATE, a.GL_CODE
#################

The UDF returns a table. The inputs are both varchars of the appropriate size. I include the PO_NUMBER to do join queries.

When I attempt to run this, I get an error like
"Line 1: Incorrect syntax near '.'."

This same query works if I hard code parameters.

Sql Server 2000 / Windows NT

Any thoughts?

Thanks in advance.
Chris."

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-22 : 10:41:29
A table valued function will not accept column values as input parameters. They must be either literals or local variables.



CODO ERGO SUM
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-09-22 : 12:15:25
Why does the UDF return a table? You're trying to use its return value as a column value in the main query so it should be a scalar value function and it would work fine.

If you use a table valued function then you use its result as a table and join it to your other data, don't call it in a row where you need a scalar value.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-22 : 12:38:07
Why not create a stored procedure instead?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -