Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Friday, February 24, 2012

Linked Server - How to write a Query with condtion (string)

Hi all,
I have created a linked server from SQL 2k to Informix which is fine.
I wrote below query which also fine and got results:
select * from OPENQUERY
(myLinkServer, 'select a.emp_number,a.emp_name,a.emp_loc,a.emp_stat,
b.emp_grade,b.emp_title from employee a,title b where a.emp_number =
b.emp_number')
But, I need to add folliwng condition with above query that I tried. But
no luck getting error.
How can I incorporate belwo condition with above linked server query:
and a.join_date =' 04/09/2005' and a.emp_loc = 'LON'
Kindly note, "join_date" value and "emp_loc" values can be passed via a
variables.
Appreciate all your help.
Regards
*** Sent via Developersdex http://www.examnotes.net ***Hi
Try:
SELECT emp_number, emp_name, emp_loc, emp_stat, emp_grade, emp_title
FROM OPENQUERY
(myLinkServer, 'select a.emp_number,a.emp_name,a.emp_loc,a.emp_stat,
b.emp_grade,b.emp_title,a.join_date from employee a,title b where
a.emp_number =
b.emp_number') Q
WHERE join_date =' 04/09/2005'
AND emp_loc = 'LON'
John
"Ahmed Jewahar" <ahmed.jewahar@.dhl.com> wrote in message
news:%23y047zZPFHA.4052@.TK2MSFTNGP12.phx.gbl...
> Hi all,
> I have created a linked server from SQL 2k to Informix which is fine.
> I wrote below query which also fine and got results:
> select * from OPENQUERY
> (myLinkServer, 'select a.emp_number,a.emp_name,a.emp_loc,a.emp_stat,
> b.emp_grade,b.emp_title from employee a,title b where a.emp_number =
> b.emp_number')
>
> But, I need to add folliwng condition with above query that I tried. But
> no luck getting error.
> How can I incorporate belwo condition with above linked server query:
>
> and a.join_date =' 04/09/2005' and a.emp_loc = 'LON'
>
> Kindly note, "join_date" value and "emp_loc" values can be passed via a
> variables.
> Appreciate all your help.
> Regards
>
> *** Sent via Developersdex http://www.examnotes.net ***|||Ahmed
I suggest you create a stored procedure that accepts two parameters
DECLARE @.SQLx VARCHAR(500)
DECLARE @.var VARCHAR(20)
SET @.var = 'abcd'
SET @.SQLx = 'SELECT * FROM OPENQUERY(Server,
''EXEC pubs.dbo.sp2 '' + @.var + '')'
EXEC(@.SQLx)
"Ahmed Jewahar" <ahmed.jewahar@.dhl.com> wrote in message
news:%23y047zZPFHA.4052@.TK2MSFTNGP12.phx.gbl...
> Hi all,
> I have created a linked server from SQL 2k to Informix which is fine.
> I wrote below query which also fine and got results:
> select * from OPENQUERY
> (myLinkServer, 'select a.emp_number,a.emp_name,a.emp_loc,a.emp_stat,
> b.emp_grade,b.emp_title from employee a,title b where a.emp_number =
> b.emp_number')
>
> But, I need to add folliwng condition with above query that I tried. But
> no luck getting error.
> How can I incorporate belwo condition with above linked server query:
>
> and a.join_date =' 04/09/2005' and a.emp_loc = 'LON'
>
> Kindly note, "join_date" value and "emp_loc" values can be passed via a
> variables.
> Appreciate all your help.
> Regards
>
> *** Sent via Developersdex http://www.examnotes.net ***|||Hi Uri,
Thanks for you kind help..
Regards,
*** Sent via Developersdex http://www.examnotes.net ***|||Hi John,
Thanks for your great help. I tried the same and it has been resolved my
problem,
Regards
*** Sent via Developersdex http://www.examnotes.net ***|||Hi
The only issue may be that the openquery may still return an excessivly
large number of rows before being reduced by the subsequent where clause.
John
"Ahmed Jewahar" <ahmed.jewahar@.dhl.com> wrote in message
news:umzwGEcPFHA.2760@.TK2MSFTNGP10.phx.gbl...
> Hi John,
> Thanks for your great help. I tried the same and it has been resolved my
> problem,
> Regards
>
> *** Sent via Developersdex http://www.examnotes.net ***

Monday, February 20, 2012

Linked server

Hi
I want to use the linked server. Can anyone write me the
step by step method to configure the Linked server.
Scenario:
PC1:
Server Name :DBServer1
DB Name : Customer (MS SQL 2000)
userid: guest
Pwd: guest
PC2:
Server Name :DBServer2
DB Name : Vendors (MS SQL 2000)
userid: guest
Pwd: guest
1. When I use th Enterprise Manager what are the settings
to be done in PC1 and PC2 for configuring the Linked
server.
2. Any pointer for the good web site ..?
3. Also is there a way that I can avoid using the four
part name like
linked_server_name.catalog.schema.object_name using any
global variable or namespace kind of thing....'?
Please help...
Thanks in advance.
Anand.Hi Hari
Can you send it to gurusanand1@.sifymail.com and not to the
news group.
B'coz till now I can't find your attachment.
Thanks in advance.
Anand.
>--Original Message--
>Hi Anand,
>Attached the step by step method to configure linked
server.
>Thanks
>Hari - MCDBA
>US Software
>Trivandrum
>
>"Anand" <gurusanand1@.sifymail.com> wrote in message
>news:0b6501c3567f$a691e380$a101280a@.phx.gbl...
>> Hi
>> I want to use the linked server. Can anyone write me the
>> step by step method to configure the Linked server.
>> Scenario:
>> PC1:
>> Server Name :DBServer1
>> DB Name : Customer (MS SQL 2000)
>> userid: guest
>> Pwd: guest
>> PC2:
>> Server Name :DBServer2
>> DB Name : Vendors (MS SQL 2000)
>> userid: guest
>> Pwd: guest
>> 1. When I use th Enterprise Manager what are the
settings
>> to be done in PC1 and PC2 for configuring the Linked
>> server.
>> 2. Any pointer for the good web site ..?
>> 3. Also is there a way that I can avoid using the four
>> part name like
>> linked_server_name.catalog.schema.object_name using any
>> global variable or namespace kind of thing....'?
>>
>> Please help...
>> Thanks in advance.
>> Anand.
>>
>
>