Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 an odbcstring as an variable in an openrowset?

Author  Topic 

b.veenings
Yak Posting Veteran

96 Posts

Posted - 2007-11-20 : 14:41:00
hi all,

does anyone know if its possible to put an variable into an odbcstring?

this openrowset is inside an cursor wich is called from an sp

@server varchar(50),
@database varchar(50)

what i want i something like this:
SELECT a.*
FROM OPENROWSET('@server','@database';'sa';'MyPass',
'SELECT * FROM pubs.dbo.authors ORDER BY au_lname, au_fname') AS a
GO

i already tried it but he says he can not find the server and when i put it hardcoded he works fine./

cheers
benji


Need an SQLDB consultant?
check www.veeningsengineering.nl

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-11-20 : 23:01:10
see if this works

exec ('
SELECT a.*

FROM OPENROWSET(' + @server +',' + @database + ';''sa'';''MyPass'',
''SELECT * FROM pubs.dbo.authors ORDER BY au_lname, au_fname'') AS a')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-21 : 01:09:12
Some more examples here http://sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -