Calling a function from linked SQL Server

  • Calling a function from linked SQL Server received error message.

    SELECT * FROM TSTCMSDB1...usysprocess(51)

    Server: Msg 170, Level 15, State 31, Line 1

    Line 2: Incorrect syntax near '('.

    Here are function defined in the linked server.

    CREATE FUNCTION usysprocess (@spid int)

    RETURNS TABLE

    AS

    RETURN (SELECT * from sysprocesses s

    WHERE s.spid = @spid

    Thanks.

  • You normally have to specify the user name (e.g. dbo) when calling a UDF.

    Have you tried......

    SELECT * FROM TSTCMDDB1..dbo.usysprocess(51)

    ....only a guess!

  • You need to include all parts of the 4 part name in the call i.e. server.database.user.object

    Simon Sabin

    Co-author of SQL Server 2000 XML Distilled

    http://www.amazon.co.uk/exec/obidos/ASIN/1904347088


    Simon Sabin
    SQL Server MVP

    http://sqlblogcasts.com/blogs/simons

  • I agree with Simon Sabin.

  • Try SELECT * FROM TSTCMDDB1.master.dbo.usysprocess(51) but it still doesn't work. Same error message.

    Edited by - Allen_Cui on 11/14/2002 12:28:14 PM

  • I remember somewhere someone stateing they can only use it with OPENQUERY.

    I think there is a limitation in the ability to return UDF with table returns that prevents them. Or you have to turn something else on.

    However, try this to see if works.

    SELECT * FROM TSTCMDDB1.master.dbo.[usysprocess(51)]

    I don't know what will happen since I haven't tested.

    Now the other question I have is why didn't you just select from the sysprocesses table yourself? Or make an Procedure instead?

  • Antares is right...you must call it like this:

    select * from OPENQUERY(TSTCMDDB1,'select * from master.dbo.usysprocess(51)')

    -Dan


    -Dan

  • The openquery method is what we use. Works fine.

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

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