dbTalk Databases Forums  

Can't get table function to work

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Can't get table function to work in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
tshad
 
Posts: n/a

Default Can't get table function to work - 11-22-2010 , 04:50 PM






I have a table function that works fine except when used as a JOIN.

If I have a function that I am passing a parameter from a value I had gotten
from my query:

SELECT
t1.nID
FROM table1 t1
JOIN dbo.udf_somefunction(t1.nID)

I get an error:

The multi-part identifier "t1.nID" could not be bound.

This works fine if I change the select as:

SELECT
t1.nID
FROM table1 t1
JOIN dbo.udf_somefunction(10)

How can I get this to work??

Thanks,

Tom

Reply With Quote
  #2  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Can't get table function to work - 11-22-2010 , 05:44 PM






Hi Tom,

If you need to use values from one table in the joined table
expression, you need to use APPLY rather than JOIN. So you use:

SELECT t1.nID
FROM table1 AS t1
CROSS APPLY dbo.udf_somefunction(t1.nID) AS f;

Or, if you want to preserve rows that produce an empty resultset in
the applied table expression:

SELECT t1.nID
FROM table1 AS t1
OUTER APPLY dbo.udf_somefunction(t1.nID) AS f;
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.