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 2008 Forums
 Transact-SQL (2008)
 Why doesn't this work?

Author  Topic 

SMerrill
Posting Yak Master

206 Posts

Posted - 2011-06-10 : 13:17:42
Why doesn't this work?

use tempdb
go
IF OBJECT_ID (N'dbo.fn_Alert') IS NOT NULL
DROP FUNCTION dbo.fn_Alert
GO

CREATE FUNCTION dbo.fn_Alert(@alert_mask BIGINT)
RETURNS TABLE
AS RETURN
(
select @alert_mask as Mask
)
GO

SELECT * FROM dbo.fn_alert(0x4); -- this produces the expected result

DECLARE @T TABLE(alert_mask BIGINT)
INSERT INTO @T SELECT 0x4

select fn.mask, T.alert_mask from dbo.fn_alert(T.alert_mask) as fn
cross join @T as T
/* RESULT:
Msg 4104, Level 16, State 1, Line 8
The multi-part identifier "T.alert_mask" could not be bound.

*/

DROP FUNCTION dbo.fn_Alert


~ Shaun Merrill
Seattle area

SMerrill
Posting Yak Master

206 Posts

Posted - 2011-06-10 : 13:36:43
AHA ... my co-worker came up with the answer: Use CROSS APPLY instead of CROSS JOIN.
I hope someone can learn from this.

Keywords: "CANNOT PASS COLUMN NAME INTO TVF FUNCTION"

~ Shaun Merrill
Seattle area
Go to Top of Page
   

- Advertisement -