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.
Author |
Topic |
EA
Starting Member
19 Posts |
Posted - 2006-07-24 : 09:10:46
|
I've created a stored procedure on several servers. All with the same name and all in a database with same names.Now I’m trying to execute the stored procedures by executing a script.... I don’t get it to work!I can execute it successfully by starting it manually:exec [CIMPDB01\CIMT1].zz_am.dbo.usp_SpaceMonexec [CIMPDB01\CIMT2].zz_am.dbo.usp_SpaceMonand so on..... no problemBut when I try to execute it by using a script (and substitute the instance names with values taken from a table) it won’t:declare @x intdeclare @dbname varchar(500)declare @SQL nvarchar(600)set @x = 1create table #databases(ID int IDENTITY,name varchar(500))insert #databases select instancelongname from instances where actief='J'while @x <= (select max(id) from #databases)begin select @dbname = name from #databases where id = @x print @dbnameselect @SQL='exec ' + @dbname + '.zz_am.dbo.usp_SpaceMon'print @SQLexecute @SQLset @x = @x + 1enddrop table #databasesMsg 203, Level 16, State 2, Line 17The name 'exec [CIMPDB01\CIM].zz_am.dbo.usp_SpaceMon' is not a valid identifier. |
|
Kristen
Test
22859 Posts |
Posted - 2006-07-24 : 09:15:20
|
execute (@SQL)Kristen |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-24 : 09:16:58
|
... or ditch the "EXEC":select @SQL='exec ' + @dbname + '.zz_am.dbo.usp_SpaceMon'Kristen |
|
|
EA
Starting Member
19 Posts |
Posted - 2006-07-24 : 09:51:34
|
Somtimes it's that easy.... I was looking in the wrong direction and should have posted it earlier!Thank you very much! |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-24 : 10:48:50
|
"Somtimes it's that easy"Nah, its never that easy, its just a second pair of eyes that you need!Kristen |
|
|
|
|
|