all groups > sql server programming > april 2006 >
You're in the

sql server programming

group:

OPENDATASOURCE


OPENDATASOURCE FJC
4/20/2006 10:34:02 PM
sql server programming:
Hi all,
Why I can't do the following:

DECLARE @stringConnection as varchar(150)
set @stringConnection= 'Data Source=vrpims\cpims'+';'+'User
ID=sa'+';'+'Password=sa'
select @maxAttendancesVC= max(AEATT_REFNO)
from OPENDATASOURCE( 'SQLOLEDB',
@stringConnection).materprod.dbo.ae_attendances

When I try to execute the above coding the following error message comes out:

Server: Msg 170, Level 15, State 1, Line 25
Line 25: Incorrect syntax near '@stringConnection'.

Re: OPENDATASOURCE John Bell
4/21/2006 12:00:00 AM
Hi

You can not use a variable as the init_string parameter. If you really need
to do this then use dynamic SQL although your example implies that creating
a linked server may be more suitable.

John

[quoted text, click to view]

Re: OPENDATASOURCE Madhivanan
4/21/2006 3:29:58 AM
Read more about Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html

Madhivanan
Re: OPENDATASOURCE FJC
4/23/2006 4:13:01 PM
Thanks for the info mates

[quoted text, click to view]
AddThis Social Bookmark Button