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 2000 Forums
 SQL Server Development (2000)
 Inner join within Cursor

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-11-23 : 07:04:08
Scott writes "Is it possible to use a variable in place of the server name within a cursor??




declare @sqlserver varchar
set @sqlserver='ABCDEFG'

SELECT b.[originating_server],b.[name],a.step_name,a.output_file_name,a.last_run_outcome,a.last_run_date, a.last_run_time
FROM @sqlserver.msdb.dbo.sysjobsteps AS a INNER JOIN @sqlserver.msdb.dbo.sysjobs AS b
ON a.job_id = b.job_id"

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-23 : 07:16:02
for this kind of query u need to write the dynamic sql..
declare @sqlserver varchar
set @sqlserver='ABCDEFG'

Exec ('SELECT b.[originating_server],b.[name],a.step_name,a.output_file_name,a.last_run_outcome,a.last_run_date, a.last_run_time
FROM ' +@sqlserver+'.msdb.dbo.sysjobsteps AS a INNER JOIN' + @sqlserver +'.msdb.dbo.sysjobs AS b
ON a.job_id = b.job_id')

Hope this works for u ..


Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-23 : 08:05:29
provided that server is added as a Linked Server

>>Is it possible to use a variable in place of the server name within a cursor??

Why do you need Cursor?

Madhivanan

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

- Advertisement -