Showing posts with label dbo. Show all posts
Showing posts with label dbo. Show all posts

Wednesday, March 28, 2012

OPENQUERY

HI,

Can we use OPENQUERY with a parameter? Something like this:

SELECT * FROM OPENQUERY(@.SOURCE_SERVER_NAME, 'Select * from dbo.FEED')

Please let me know at the earliest. Thanks a lot,.

Mannu.

Not supported. You need to build dynamic TSQL to run it.

|||Thanks phe...sql

OPENQUERY

HI,

Can we use OPENQUERY with a parameter? Something like this:

SELECT * FROM OPENQUERY(@.SOURCE_SERVER_NAME, 'Select * from dbo.FEED')

Please let me know at the earliest. Thanks a lot,.

Mannu.

Not supported. You need to build dynamic TSQL to run it.

|||Thanks phe...

OpenQuery

OPENQUERY will solve your problem. Examples:
--This will fail:
select * from server1.bb01_db.dbo.bb01 (nolock)
where process_dt = '2002-12-02' and mid = '03301001' and
tran_dt = '2002-12-02'
--This will work if you have your linked servers set up --
correctly:
select * from openquery(server1, 'select * from
bb01_db.dbo.bb01 (nolock)
where process_dt = ''2002-12-02'' and mid = ''03301001''
and tran_dt = ''2002-12-02''')
Ths will also work
exec server1.bb01_db.dbo.sp_executesql N'select * from bb01 (nolock)
where process_dt = ''2002-12-02'' and mid = ''03301001'' and
tran_dt =''2002-12-02'''
If those are datetimes then you should use yyyymmdd especially with remote
server calls just in case the dateformats are different.
"CurtM" wrote:

> OPENQUERY will solve your problem. Examples:
> --This will fail:
> select * from server1.bb01_db.dbo.bb01 (nolock)
> where process_dt = '2002-12-02' and mid = '03301001' and
> tran_dt = '2002-12-02'
> --This will work if you have your linked servers set up --
> correctly:
> select * from openquery(server1, 'select * from
> bb01_db.dbo.bb01 (nolock)
> where process_dt = ''2002-12-02'' and mid = ''03301001''
> and tran_dt = ''2002-12-02''')
>

OpenQuery

OPENQUERY will solve your problem. Examples:
--This will fail:
select * from server1.bb01_db.dbo.bb01 (nolock)
where process_dt = '2002-12-02' and mid = '03301001' and
tran_dt = '2002-12-02'
--This will work if you have your linked servers set up --
correctly:
select * from openquery(server1, 'select * from
bb01_db.dbo.bb01 (nolock)
where process_dt = ''2002-12-02'' and mid = ''03301001''
and tran_dt = ''2002-12-02''')Ths will also work
exec server1.bb01_db.dbo.sp_executesql N'select * from bb01 (nolock)
where process_dt = ''2002-12-02'' and mid = ''03301001'' and
tran_dt =''2002-12-02'''
If those are datetimes then you should use yyyymmdd especially with remote
server calls just in case the dateformats are different.
"CurtM" wrote:
> OPENQUERY will solve your problem. Examples:
> --This will fail:
> select * from server1.bb01_db.dbo.bb01 (nolock)
> where process_dt = '2002-12-02' and mid = '03301001' and
> tran_dt = '2002-12-02'
> --This will work if you have your linked servers set up --
> correctly:
> select * from openquery(server1, 'select * from
> bb01_db.dbo.bb01 (nolock)
> where process_dt = ''2002-12-02'' and mid = ''03301001''
> and tran_dt = ''2002-12-02''')
>sql