August 8, 2007 at 7:50 pm
I have a table-valued function that I want to call using a value from another table in the SQL statement as the parameter value, like this:
select
p.*
from people p,
GetFirstAndLastGiftInfo
(p.people_guid)
where
people_guid = '565AC73F-51D9-4991-AB18-809A089F4A72'
I get the error "The multi-part identifier "p.people_guid" could not be bound."
But, the query will execute with a hard-coded value like below:
select
p.*
from
people p,
GetFirstAndLastGiftInfo
('565AC73F-51D9-4991-AB18-809A089F4A72')
where
people_guid = '565AC73F-51D9-4991-AB18-809A089F4A72'
Does anyone know if there is a way to make this work like the first call?
Thanks!
Mike
August 8, 2007 at 9:50 pm
You cannot use a column name as a parameter for a table valued function. From Books Online...
Multi-statement Table-valued Functions
CREATE FUNCTION [ owner_name. ] function_name
( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] )
RETURNS @return_variable TABLE < table_type_definition >
[ WITH < function_option > [ [,] ...n ] ]
[ AS ]
BEGIN
function_body
RETURN
END
< function_option > ::=
{ ENCRYPTION | SCHEMABINDING }
< table_type_definition > :: =
( { column_definition | table_constraint } [ ,...n ] )
--Jeff Moden
Change is inevitable... Change for the better is not.
August 8, 2007 at 9:56 pm
You can do this with SQL 2005 using the APPLY operator
August 8, 2007 at 11:26 pm
Change function GetFirstAndLastGiftInfo to a view and join it to table People on people_guid= people_guid
_____________
Code for TallyGenerator
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply