Friday, March 23, 2012

OPENDATASOURCE

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'.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
"FJC" <FJC@.discussions.microsoft.com> wrote in message
news:D1504C11-BCD1-40F0-8E88-40AB9DCE1522@.microsoft.com...
> 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'.
>|||Read more about Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html
Madhivanan|||Thanks for the info mates
"Madhivanan" wrote:

> Read more about Dynamic SQL
> http://www.sommarskog.se/dynamic_sql.html
> Madhivanan
>

No comments:

Post a Comment