Showing posts with label field1. Show all posts
Showing posts with label field1. Show all posts

Friday, March 30, 2012

OpenQuery with variable

I need to do this:
select field1, field2,... from openquery(LinkedServerName, 'select * from
tablename where field =' + @.myVar)
the problem is that openquery does not admit statement to be composed by
concatted strings...how to solve it?You need to build the entire SQL statement as a string and
then pass that string to an EXEC.
You can find more information and an example in the
following article:
HOW TO: Pass a Variable to a Linked Server Query
http://support.microsoft.com/?id=314520
-Sue
On Tue, 24 Jan 2006 08:52:01 -0800, "Roberto Lo Baido"
<RobertoLoBaido@.discussions.microsoft.com> wrote:
>I need to do this:
>select field1, field2,... from openquery(LinkedServerName, 'select * from
>tablename where field =' + @.myVar)
>the problem is that openquery does not admit statement to be composed by
>concatted strings...how to solve it?

OpenQuery with variable

I need to do this:
select field1, field2,... from openquery(LinkedServerName, 'select * from
tablename where field =' + @.myVar)
the problem is that openquery does not admit statement to be composed by
concatted strings...how to solve it?You need to build the entire SQL statement as a string and
then pass that string to an EXEC.
You can find more information and an example in the
following article:
HOW TO: Pass a Variable to a Linked Server Query
http://support.microsoft.com/?id=314520
-Sue
On Tue, 24 Jan 2006 08:52:01 -0800, "Roberto Lo Baido"
<RobertoLoBaido@.discussions.microsoft.com> wrote:

>I need to do this:
>select field1, field2,... from openquery(LinkedServerName, 'select * from
>tablename where field =' + @.myVar)
>the problem is that openquery does not admit statement to be composed by
>concatted strings...how to solve it?sql

OPENQUERY UPDATE Syntax help needed

Hi All

I am updating a local table based on inner join between local table
and remote table.

Update LocalTable
SET Field1 = B.Field1
FROM LinkedServer.dbname.dbo.RemoteTable B
INNER JOIN LocalTable A
ON B.Field2 = A.Field2
AND B.Field3 = A.Field3

This query takes 18 minutes to run.
I am hoping to speed up the process by writing in OPENQUERY syntax.

Thanks
RS(rshivaraman@.gmail.com) writes:

Quote:

Originally Posted by

I am updating a local table based on inner join between local table
and remote table.
>
Update LocalTable
SET Field1 = B.Field1
FROM LinkedServer.dbname.dbo.RemoteTable B
INNER JOIN LocalTable A
ON B.Field2 = A.Field2
AND B.Field3 = A.Field3
>
This query takes 18 minutes to run.
I am hoping to speed up the process by writing in OPENQUERY syntax.


UPDATE LocalTable
SET Field1 = B.Field1
FROM OPENQUERY(LINKEDSERVER,
'SELECT Field1, Field2, Field3 FROM dbname.dbo.RemoteTable) B
INNER JOIN LocalTable A
ON B.Field2 = A.Field2
AND B.Field3 = A.Field3

I would not really expect this to perform better.

Distributed queries are always difficult, but it's difficult to suggest
anything without further knowledge about the table. How big are the
two tables?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx