Friday, March 23, 2012

Opendatasource

What is the syntax for using parameters in an opendatasource query? I tried using the below:

SELECT top 10 *
FROM OPENDATASOURCE(
'SQLOLEDB',
'Data Source=10.22.10.78;User ID='+@.user+';Password='+@.pword
).Northwind.dbo.Categoriesad-hoc (i.e. openquery/openrowset/opendatasource) only accepts string literals. You have to formulate your entire opendatasource query and execute it.

e.g.
set @.sql='select *
from opendatasource(...)'

exec(@.sql)|||Nothing really happens when I try to exec the following, Is my syntax correct?:

Declare @.user as varchar(25)
Declare @.pword as varchar(25)
Declare @.Cstring as varchar(500)

Set @.cString = 'SELECT top 10 SOPNUMBE, TRXDATE, LNITMSEQ, [DB_ID], AccountId, XTNDPRCE
FROM OPENDATASOURCE(
' + 'SQLOLEDB' + ',' +
'Data Source=server1;User ID=' + @.user + ';Password=' + @.pword + '
).dw1.dbo.Table1'

exec (@.cstring)|||Wasn't entering the username and password. Is there a way to make this an Insert statement?|||insert into what? like this?

--set @.sql='your select query'

insert tb
exec(@.sql)

No comments:

Post a Comment