here is the code:
if exists (select [id] from master..sysobjects where [id] = OBJECT_ID ('master..temp_startime '))
DROP TABLE temp_startime
declare @sql nvarchar(4000)
declare @db varchar(300)
set @db = 'master'
declare cDB cursor for
SELECT name from master..sysdatabases sdb
WHERE sdb.name like 'client_%'
--and sdb.crdate >= '10/1/2007'
ORDER BY name
CREATE TABLE temp_startime([Server Name] nvarchar(40),
[Database Name] nvarchar(100),
[Files ID] int,
[Start Date] datetime,
[Count] int
)
open cDB
FETCH NEXT FROM cDB INTO @db
while (@@fetch_status = 0)
begin
SET @sql = 'SELECT @@SERVERNAME as ''[Server Name]'', ' +
'''' + @db + '''' + ' as ''[Database Name]'',' +
'a.[id] as ''[Files ID]'',' +
'd.startTime as ''[Start Date]'',' +
'count(*) as ''[Count]''' +
'FROM ' + @db + '.dbo.filo_files a join ' + @db + '.dbo.semantica_corpora b on a.[id] = b.documentkey ' +
'join ' + @db + '.dbo.filo_assignments c on on b.projectkey = c.[id] join ' + @db + '.dbo.filo_processlog d on c.lastprocesskey = d.[id] WHERE task = ''Create Assignments''' +
'and d.startTime >= ''9/1/2007'' AND d.startTime <= ''9/30/2007'' group by a.[id], d.startTime'
/*
select a.[id],d.starttime
from filo_files a
join semantica_corpora b on a.[id] = b.documentkey
join filo_assignments c on b.projectkey = c.id
join filo_processlog d on c.lastprocesskey = d.id
where d.task = 'Create Assignments' and d.starttime >= '9/1/2007' AND d.starttime <= '9/30/2007'
group by a.[id],d.starttime
*/
INSERT temp_startime
EXEC sp_executesql @sql
fetch cDB into @db
end
close cDB
deallocate cDB
select * from temp_startime
and I am getting this error message:
Server: Msg 170, Level 15, State 1, Line 39
Line 39: Incorrect syntax near 'and d.startTime >= '9/1/2007' AND d.startTime <= '9/30/2007' group by a.[id], d.startTime'.
I'm still struggling with this stuff!!!!
Thank you for your help in advanced!!!!
Tammy
if exists (select [id] from master..sysobjects where [id] = OBJECT_ID ('master..temp_startime '))
DROP TABLE temp_startime
declare @sql nvarchar(4000)
declare @db varchar(300)
set @db = 'master'
declare cDB cursor for
SELECT name from master..sysdatabases sdb
WHERE sdb.name like 'client_%'
--and sdb.crdate >= '10/1/2007'
ORDER BY name
CREATE TABLE temp_startime([Server Name] nvarchar(40),
[Database Name] nvarchar(100),
[Files ID] int,
[Start Date] datetime,
[Count] int
)
open cDB
FETCH NEXT FROM cDB INTO @db
while (@@fetch_status = 0)
begin
SET @sql = 'SELECT @@SERVERNAME as ''[Server Name]'', ' +
'''' + @db + '''' + ' as ''[Database Name]'',' +
'a.[id] as ''[Files ID]'',' +
'd.startTime as ''[Start Date]'',' +
'count(*) as ''[Count]''' +
'FROM ' + @db + '.dbo.filo_files a join ' + @db + '.dbo.semantica_corpora b on a.[id] = b.documentkey ' +
'join ' + @db + '.dbo.filo_assignments c on on b.projectkey = c.[id] join ' + @db + '.dbo.filo_processlog d on c.lastprocesskey = d.[id] WHERE task = ''Create Assignments''' +
'and d.startTime >= ''9/1/2007'' AND d.startTime <= ''9/30/2007'' group by a.[id], d.startTime'
/*
select a.[id],d.starttime
from filo_files a
join semantica_corpora b on a.[id] = b.documentkey
join filo_assignments c on b.projectkey = c.id
join filo_processlog d on c.lastprocesskey = d.id
where d.task = 'Create Assignments' and d.starttime >= '9/1/2007' AND d.starttime <= '9/30/2007'
group by a.[id],d.starttime
*/
INSERT temp_startime
EXEC sp_executesql @sql
fetch cDB into @db
end
close cDB
deallocate cDB
select * from temp_startime
and I am getting this error message:
Server: Msg 170, Level 15, State 1, Line 39
Line 39: Incorrect syntax near 'and d.startTime >= '9/1/2007' AND d.startTime <= '9/30/2007' group by a.[id], d.startTime'.
I'm still struggling with this stuff!!!!
Thank you for your help in advanced!!!!
Tammy