hi!
I am having an error
Server: Msg 170, Level 15, State 1, Line 38
Line 38: Incorrect syntax near ' .dbo.filo_files b on a.[id] = b.ownerkey WHERE b.parentFileKey Is Null'.
I don't see what is wrong.
Maybe I cannot have a join in a string?
The code is below.
Thanks!
--1) We are creating and populating the table temp_Source_Media_file_count with SOURCE MEDIA file information.
if exists (select [id] from master..sysobjects where [id] = OBJECT_ID ('master..temp_Source_Media_file_count '))
DROP TABLE temp_Source_Media_file_count
declare @sql1 nvarchar(4000)
declare @db1 varchar(300)
set @db1 = 'master'
declare cDB1 cursor for
SELECT name from master..sysdatabases sdb
WHERE sdb.crdate >= '10/1/2007' and sdb.name like 'client_%'
ORDER BY name
CREATE TABLE temp_Source_Media_file_count([Server Name] nvarchar(40),
[Database Name] nvarchar(100),
[Custodian Name] nvarchar(300),
[Create Date] datetime,
[Original File Count] int,
[Original File Size (MB)] decimal(10,4)
)
open cDB1
FETCH NEXT FROM cDB1 INTO @db1
while (@@fetch_status = 0)
begin
SET @sql1 = 'SELECT SELECT @@SERVERNAME as ''[Server Name]'', ' +
'''' + @db1 + '''' + ' as ''[Database Name]'',' +
'a.name as ''[Custodian Name]'',' +
'NULL as ''[Create Date]'',' +
'count(*) as ''[Original File Count]'',' +
'(cast(Sum(ff.length) as decimal)/1048576) as ''[Original File Size (MB)]''' +
'FROM ' + @db1 + '.dbo.filwners a left join ' + @db1 + ' .dbo.filo_files b on a.[id] = b.ownerkey WHERE b.parentFileKey Is Null GROUP BY a.name'
INSERT temp_Source_Media_file_count
EXEC sp_executesql @sql1
fetch cDB1 into @db1
end
close cDB1
deallocate cDB1
UPDATE temp_Source_Media_file_count
SET temp_Source_Media_file_count.[Create Date]
= (SELECT crDate
FROM master..sysdatabases AS C1
WHERE C1.name = temp_Source_Media_file_count.[Database Name])
select * from temp_Source_Media_file_count
I am having an error
Server: Msg 170, Level 15, State 1, Line 38
Line 38: Incorrect syntax near ' .dbo.filo_files b on a.[id] = b.ownerkey WHERE b.parentFileKey Is Null'.
I don't see what is wrong.
Maybe I cannot have a join in a string?
The code is below.
Thanks!
--1) We are creating and populating the table temp_Source_Media_file_count with SOURCE MEDIA file information.
if exists (select [id] from master..sysobjects where [id] = OBJECT_ID ('master..temp_Source_Media_file_count '))
DROP TABLE temp_Source_Media_file_count
declare @sql1 nvarchar(4000)
declare @db1 varchar(300)
set @db1 = 'master'
declare cDB1 cursor for
SELECT name from master..sysdatabases sdb
WHERE sdb.crdate >= '10/1/2007' and sdb.name like 'client_%'
ORDER BY name
CREATE TABLE temp_Source_Media_file_count([Server Name] nvarchar(40),
[Database Name] nvarchar(100),
[Custodian Name] nvarchar(300),
[Create Date] datetime,
[Original File Count] int,
[Original File Size (MB)] decimal(10,4)
)
open cDB1
FETCH NEXT FROM cDB1 INTO @db1
while (@@fetch_status = 0)
begin
SET @sql1 = 'SELECT SELECT @@SERVERNAME as ''[Server Name]'', ' +
'''' + @db1 + '''' + ' as ''[Database Name]'',' +
'a.name as ''[Custodian Name]'',' +
'NULL as ''[Create Date]'',' +
'count(*) as ''[Original File Count]'',' +
'(cast(Sum(ff.length) as decimal)/1048576) as ''[Original File Size (MB)]''' +
'FROM ' + @db1 + '.dbo.filwners a left join ' + @db1 + ' .dbo.filo_files b on a.[id] = b.ownerkey WHERE b.parentFileKey Is Null GROUP BY a.name'
INSERT temp_Source_Media_file_count
EXEC sp_executesql @sql1
fetch cDB1 into @db1
end
close cDB1
deallocate cDB1
UPDATE temp_Source_Media_file_count
SET temp_Source_Media_file_count.[Create Date]
= (SELECT crDate
FROM master..sysdatabases AS C1
WHERE C1.name = temp_Source_Media_file_count.[Database Name])
select * from temp_Source_Media_file_count