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 |
|
sr69
Starting Member
2 Posts |
Posted - 2008-07-31 : 13:41:18
|
| I have the code below, but it returns the following error "Must declare the scalar variable "@Dom" "Note: The problem is when I insert the @Dom variable.Regards/******************************************************************/Create table #DB ( DomainName varchar (100),ServerName VARCHAR(100),DBName VARCHAR (100)) DECLARE @command VARCHAR(500) DECLARE @Dom varchar(50)set @Dom='ACME'SET @command= 'Use [' + '?' + '] select @Dom as DomainName, @@Servername as ServerName, ' + '''' + '?' + '''' + ' AS DBName'INSERT INTO #DB ( DomainName, ServerName, DBName ) EXEC sp_MSForEachDB @command SELECT * FROM #DB drop table #DB/****************************************************************/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-31 : 13:44:02
|
| You cant use variables inside a sql string and use them in exec statements. the variable will be out of scope. Can i ask what you're trying to do with sp_MSForEachDB ? |
 |
|
|
contrari4n
Starting Member
27 Posts |
Posted - 2008-07-31 : 14:38:40
|
| Is this what you are trying to do?SELECT 'ACME' AS DomainName, @@ServerName AS ServerName, name AS DBNameFROM sys.databasesRichard Fryarhttp://www.sql-server-pro.comSQL Server Articles and Tips |
 |
|
|
sr69
Starting Member
2 Posts |
Posted - 2008-08-01 : 09:52:52
|
Hi it's clear for me now thanks, I'm trying to get some statistics for db growth.Regardssr69quote: Originally posted by visakh16 You cant use variables inside a sql string and use them in exec statements. the variable will be out of scope. Can i ask what you're trying to do with sp_MSForEachDB ?
|
 |
|
|
|
|
|