Remote user defind functions

  • Hi.

    I have a user defined function who returns a table. This function works fine, but I want to call her from other DB. When I try to call her in the form SELECT * FROM server.db.dbo.fnMyFunction(param) this error raises:

    "Line 2: Incorrect syntax near '('."

    And the syntax is "correct".

    ¿Exist a special issue? ¿How can I call a remote UDF?

    Thanks

  • Interesting...

    It doesn't work with a param unless you use dynamic SQL, but here's something to start with...

    select * from openquery(Server, 'Select * From db.dbo.fnMyFunctionName()' ) T1



    Once you understand the BITs, all the pieces come together

  • Seems 4 part UDF naming conventions are NOT supported in SQL2K.

    see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q319138



    Once you understand the BITs, all the pieces come together

  • Arrrghh.

    That's ugly. I need the result table to perform joins on local tables.

    I think I will duplicate the function on local DB using remote tables. Seems to be more elegant.

    Thanks for your help Thomas.

  • You can always insert into a #Temp table using either OpenQuery or Server.DB.dbo.sp_Execute ...,

    then JOIN the #Temp table. This may be better for the optimizer to deal with anyway.



    Once you understand the BITs, all the pieces come together

  • Thanks, I'll consider it.

    Now I have another problem with this UDF. I'm trying to put an optional parameter inside this UDF, but doesn't seem to be accepted.

    I've tryed a similar case in one SP and there worked fine.

    I'm searching in Internet and BOL, but I can't find anything.

    Do you know somethig about it?

  • Off the top, I think both SPs and UDF can have default values, but UDFs require at least a NULL in each params.

     



    Once you understand the BITs, all the pieces come together

  • Maybe I don't understand your response, but if I need at least a NULL for @param2, isn't optional. I'm right?

    I have:

    create function dbo.MyFn(@param1 varchar(10), @param2 varchar(10) = 'No input') as
    ...

    And try to execute it:

    select * from dbo.MyFn('value1')

    I get:

    "Server: Msg 313, Level 16, State 3, Line 1

    An insufficient number of arguments were supplied for the procedure or function dbo.MyFn."

    Thanks

  • Yes, in my exper. also... you need to...

    select * from dbo.MyFn('value1', NULL) --- at the very least

    Oh well, SQL's 1st time with UDFs, so I guess we get a lot of what we want, just not everything we would want.

     



    Once you understand the BITs, all the pieces come together

  • Jejeje, 🙂

    Thanks

Viewing 10 posts - 1 through 9 (of 9 total)

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