hi!
Im running the folowing code to loop through all the databases and
insert the results in a temp table.
In this case I need to run a join within a @sql string, but it does
not work.
Any ideas on how I can achieve this?
Here is my code:
if exists (select [id] from master..sysobjects where [id] = OBJECT_ID
('master..temp_files_to_review '))
DROP TABLE temp_files_to_review
declare @sql6 nvarchar(4000)
declare @db6 varchar(300)
set @db6 = 'master'
declare cDB6 cursor for
SELECT name from master..sysdatabases sdb
WHERE sdb.crdate >= '09/01/2007' and sdb.name like 'client_%'
ORDER BY name
CREATE TABLE temp_files_to_review([Server Name]
nvarchar(40),
[Database Name]
nvarchar(100),
[Create Date] datetime,
[To review File Count]
int,
[To review File Size (MB)] decimal(10,4)
)
open cDB6
FETCH NEXT FROM cDB6 INTO @db6
while (@@fetch_status = 0)
begin
set @sql6 = 'SELECT @@SERVERNAME as ''[Server
Name]'', ' +
'''' + @db6 + '''' +
' as ''[Database Name]'', ' +
'NULL as ''[Create Date]'',' +
' count(id) as ''[To review File Count]'', ' +
'(cast(Sum(length) as decimal)/1048576) as ''[To review File
Size (MB)]''' +
' FROM ' + @db6 + '.dbo.from filo_files where id in (select
documentkey from ' + @db6 + '.dbo.semantica_corpora where projectkey
in (select distinct id from ' + @db6 + '.dbo.filo_assignments where
status <> ''removed''))'
INSERT temp_files_to_review
EXEC sp_executesql @sql6
fetch cDB6 into @db6
end
close cDB6
deallocate cDB6
Thanks in advance.
Tammy
Im running the folowing code to loop through all the databases and
insert the results in a temp table.
In this case I need to run a join within a @sql string, but it does
not work.
Any ideas on how I can achieve this?
Here is my code:
if exists (select [id] from master..sysobjects where [id] = OBJECT_ID
('master..temp_files_to_review '))
DROP TABLE temp_files_to_review
declare @sql6 nvarchar(4000)
declare @db6 varchar(300)
set @db6 = 'master'
declare cDB6 cursor for
SELECT name from master..sysdatabases sdb
WHERE sdb.crdate >= '09/01/2007' and sdb.name like 'client_%'
ORDER BY name
CREATE TABLE temp_files_to_review([Server Name]
nvarchar(40),
[Database Name]
nvarchar(100),
[Create Date] datetime,
[To review File Count]
int,
[To review File Size (MB)] decimal(10,4)
)
open cDB6
FETCH NEXT FROM cDB6 INTO @db6
while (@@fetch_status = 0)
begin
set @sql6 = 'SELECT @@SERVERNAME as ''[Server
Name]'', ' +
'''' + @db6 + '''' +
' as ''[Database Name]'', ' +
'NULL as ''[Create Date]'',' +
' count(id) as ''[To review File Count]'', ' +
'(cast(Sum(length) as decimal)/1048576) as ''[To review File
Size (MB)]''' +
' FROM ' + @db6 + '.dbo.from filo_files where id in (select
documentkey from ' + @db6 + '.dbo.semantica_corpora where projectkey
in (select distinct id from ' + @db6 + '.dbo.filo_assignments where
status <> ''removed''))'
INSERT temp_files_to_review
EXEC sp_executesql @sql6
fetch cDB6 into @db6
end
close cDB6
deallocate cDB6
Thanks in advance.
Tammy