Solved

Can I execute a user defined function in a linked server

Posted on 2002-04-25
2
344 Views
Last Modified: 2012-08-14
I have two sql servers, named mainserver and linkedserver
I want to do a

select *
from linkedserver.database.dbo.table
where field = 'something'

on the mainserver and I noticed that this is quite a performance hit, because where clause of the query is apparantly executed on the mainserver.

So I considered creating a function on the linkedserver:

CREATE FUNCTION func(@sWhere char())
RETURNS TABLE AS
RETURN (
SELECT *
FROM database.dbo.table
WHERE field = @sWhere
)

I can execute this function on linkedserver, but not on mainserver, it gives me:

SELECT * FROM linkedserver.database.dbo.func('abcde')

Server: Msg 170, Level 15, State 31, Line 2
Line 3: Incorrect syntax near '('.

Any ideas?

thanks,

Mark
0
Comment
Question by:tetrode
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 150 total points
ID: 6968471
The linked server does not support executing function and stored procedures.

Now, as far as i know, you might try to use the OPENQUERY and/or OPENROWSET functions, which should be able to pass the query completely to the "linkedserver"...
CHeers
0
 
LVL 1

Author Comment

by:tetrode
ID: 6968801
Excellent. You not only answered fast, but understood my problem and provided a solution that works!

0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question