Solved

Can I execute a user defined function in a linked server

Posted on 2002-04-25
2
319 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 142

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now