troubleshooting Question

Table function input parameters

Avatar of feezus
feezus asked on
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008
7 Comments2 Solutions716 ViewsLast Modified:
For you SQL experts.  I am running MS SQL 2008.  

I have a function to flatten/pivot a user's data.  The function call:
select * from dbo.fnPivotUserData(1234)

returns a single-row table with four fields: PersonID, Data1, Data2, Data3

and works well enough for what's needed.  Could someone tell me, why does the following work:
select p.PersonName, d.Data1, d.Data2, d.Data3
from tblPerson p left outer join 
	dbo.fnPivotUserData(1234) d on p.PersonID = d.PersonID
where p.PersonID = 1234

But the following does not:
select p.PersonName, d.Data1, d.Data2, d.Data3
from tblPerson p left outer join 
	dbo.fnPivotUserData(p.PersonID) d on p.PersonID = d.PersonID
where p.PersonID = 1234

The only difference is the input parameter for the function call; in return, I am told 'The multi-part identifier "p.PersonID" could not be bound'.   So, in short, why can I not pass p.PersonID as the input parameter when I join to this function as a table?

(note:  I know the join could easily be a cross join, but that's not my issue)


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros