How to call a udf that's on a linked server

  • I get the following error when running a query with this udf, [BRO-DR01].testfdb.dbo.fnInsurance(SourceID, VisitID, 1). So, the function is on server, BRO-DR01, but I'm running the query on server, SH-SQL01. Any thoughts?

    Msg 207, Level 16, State 1, Procedure spDischargeFollowUp_61, Line 55

    Invalid column name 'BRO-DR01'.

  • How straightforward is your function 'dbo.fnInsurance'? Is it possible to create a function from SH-SQL01 utilising the linked server?

    I think one option is to use OpenQuery: https://msdn.microsoft.com/en-gb/library/ms188427(v=sql.100).aspx

    E.g

    SELECT *

    FROM OPENQUERY(BRO-DR01,'testfdb.dbo.fnInsurance(1, 1, 1)')

    There's drawbacks though - you can't use parameters in OpenQuery so would need dynamic sql which opens up another can of worms. I've not used it in practice so couldn't recommend it, but if needed you can research it as an option (or someone here can advise). Not sure what performance implications are either.

  • Yuck. In my case the function eliminates a table join so, maybe I'll just do the join.

  • You would get a better answer if you posted the query that is giving you the error. Without that all you will get is a shot in the dark.

  • I understand. I'm going to by pass the function and join the tables to get the data.

  • Are you still pulling data across the linked server?

  • Yes.

  • NineIron (2/25/2016)


    Yes.

    Please post the original query and the query you are using now without the function.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply