Hi!
I am trying to loop through all the databases using cursor.
Here is my stored proc
if exists (select [id] from master..sysobjects where [id] = OBJECT_ID
('master..temp_Assignments_file_count '))
DROP TABLE temp_Assignments_file_count
declare @.sql nvarchar(4000)
declare @.db varchar(300)
set @.db = 'master'
declare cDB cursor for
SELECT name from master..sysdatabases sdb
WHERE sdb.crdate >= '2007-10-01' and sdb.name like 'client_%'
ORDER BY name
CREATE TABLE temp_Assignments_file_count([Server Name]
nvarchar(40),
[Database Name]
nvarchar(100),
[Title] nvarchar(100),
[File Count] int,
[File Size (MB)] decimal(10,4),
)
open cDB
FETCH NEXT FROM cDB INTO @.db
while (@.@.fetch_status = 0)
begin
SET @.sql = 'SELECT @.@.SERVERNAME as ''[Server
Name]'', ' +
'''' + @.db + '''' + '
as ''[Database Name]'', ' +
'max(b.title) as ''[Title]'',' +
'count(*) as ''[File Count]'',' +
'round(cast(sum(length) as decimal)/1048576/1024,10) as
''[File Size]''' +
'from ' + @.db + '.dbo.filo_files a join (select b.id from ' +
@.db + 'dbo.filo_Matters b) on a.matterkey = b.id' +
'where a.id in (select distinct documentkey from ' + @.db +
'.dbo.semantica_corpora where projectkey in (select id from ' + @.db +
'.dbo.filo_assignments' +
'where lastprocesskey in (select id from ' + @.db +
'.dbo.filo_processlog where task = ''Create Assignments'' and
starttime >= ''10/01/2007'' AND starttime <= ''09/30/2007'')))' +
'and a.id not in (select distinct documentkey from ' + @.db +
'.dbo.semantica_corpora where projectkey in (select id from ' + @.db +
'.dbo.filo_assignments where lastprocesskey in' +
'(select id from ' + @.db + '.dbo.filo_processlog where task = ''Create Assignments'' and starttime < ''10/01/2007'')))'
INSERT temp_Assignments_file_count
EXEC sp_executesql @.sql
fetch cDB into @.db
end
close cDB
deallocate cDB
select * from temp_Assignments_file_count
I am getting the following error messages:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'on'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'in'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'on'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'in'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'on'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'in'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'on'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'in'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'on'.
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'in'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
(0 row(s) affected)
any help would be appreciated.
TGDo:
PRINT @.sql
before you try to execute what you have in the variable and you will find a lot of problems with the
query that you built. Based on that you can debug your code so it produces a valid query.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
<jtammyg@.gmail.com> wrote in message news:1192645043.161544.136800@.v29g2000prd.googlegroups.com...
> Hi!
> I am trying to loop through all the databases using cursor.
> Here is my stored proc
> if exists (select [id] from master..sysobjects where [id] = OBJECT_ID
> ('master..temp_Assignments_file_count '))
> DROP TABLE temp_Assignments_file_count
>
> declare @.sql nvarchar(4000)
> declare @.db varchar(300)
>
> set @.db = 'master'
> declare cDB cursor for
> SELECT name from master..sysdatabases sdb
> WHERE sdb.crdate >= '2007-10-01' and sdb.name like 'client_%'
> ORDER BY name
>
> CREATE TABLE temp_Assignments_file_count([Server Name]
> nvarchar(40),
> [Database Name]
> nvarchar(100),
> [Title] nvarchar(100),
> [File Count] int,
> [File Size (MB)] decimal(10,4),
> )
>
> open cDB
> FETCH NEXT FROM cDB INTO @.db
> while (@.@.fetch_status = 0)
> begin
> SET @.sql = 'SELECT @.@.SERVERNAME as ''[Server
> Name]'', ' +
> '''' + @.db + '''' + '
> as ''[Database Name]'', ' +
> 'max(b.title) as ''[Title]'',' +
> 'count(*) as ''[File Count]'',' +
> 'round(cast(sum(length) as decimal)/1048576/1024,10) as
> ''[File Size]''' +
> 'from ' + @.db + '.dbo.filo_files a join (select b.id from ' +
> @.db + 'dbo.filo_Matters b) on a.matterkey = b.id' +
> 'where a.id in (select distinct documentkey from ' + @.db +
> '.dbo.semantica_corpora where projectkey in (select id from ' + @.db +
> '.dbo.filo_assignments' +
> 'where lastprocesskey in (select id from ' + @.db +
> '.dbo.filo_processlog where task = ''Create Assignments'' and
> starttime >= ''10/01/2007'' AND starttime <= ''09/30/2007'')))' +
> 'and a.id not in (select distinct documentkey from ' + @.db +
> '.dbo.semantica_corpora where projectkey in (select id from ' + @.db +
> '.dbo.filo_assignments where lastprocesskey in' +
> '(select id from ' + @.db + '.dbo.filo_processlog where task => ''Create Assignments'' and starttime < ''10/01/2007'')))'
>
> INSERT temp_Assignments_file_count
> EXEC sp_executesql @.sql
>
> fetch cDB into @.db
> end
> close cDB
> deallocate cDB
>
> select * from temp_Assignments_file_count
>
>
> I am getting the following error messages:
>
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'on'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'in'.
> Server: Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near ')'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'on'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'in'.
> Server: Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near ')'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'on'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'in'.
> Server: Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near ')'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'on'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'in'.
> Server: Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near ')'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'on'.
> Server: Msg 156, Level 15, State 1, Line 1
> Incorrect syntax near the keyword 'in'.
> Server: Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near ')'.
> (0 row(s) affected)
>
> any help would be appreciated.
> TG
>
Showing posts with label master. Show all posts
Showing posts with label master. Show all posts
Friday, March 9, 2012
Wednesday, March 7, 2012
Error Message: Transaction cannot start while in firehose mode
Hi,
I am dealing with an application where the back-end is SqlServer2000. There
is a master table where one filed is empty that needs to be filled in with
correct value. As I am trying to add the value to this field on a particular
row, I am getting the following message: Transaction cannot start while in
firehose mode. Now I am planning to send a update command to the particular
row to fill in the blank value for the field concerned. However, before I do
that I just want to know, why I am getting the above error. Any help is
appreciated. Thanks.> As I am trying to add the value to this field on a particular row
How are you "trying to add the value"? An update statement, a stored
procedure call, pasting into Enterprise Manager's "Open Table" view, ...
--
http://www.aspfaq.com/
(Reverse address to reply.)|||I was trying to add the blank field value from Enterprise Manager, by right
clicking and opening the table and choosing all row option and then going to
the right record and the blank field to fill it up. At this point, I got the
above message. I would like to know why I am getting such message and is it
safe to run a update query to update the blank field in one record via Query
Analyzer. Thanks
"Aaron [SQL Server MVP]" wrote:
> > As I am trying to add the value to this field on a particular row
> How are you "trying to add the value"? An update statement, a stored
> procedure call, pasting into Enterprise Manager's "Open Table" view, ...
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>|||If your table has a primary key (or a unique way to identify a single row),
then yes, I would use an UPDATE statement in Query Analyzer. Enterprise
Manager has its purposes, but data manipulation is not one of them. Please
have a look through this article: http://www.aspfaq.com/2455
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:C2FBA83A-46B0-4F54-85CA-7D829462E75B@.microsoft.com...
> I was trying to add the blank field value from Enterprise Manager, by
right
> clicking and opening the table and choosing all row option and then going
to
> the right record and the blank field to fill it up. At this point, I got
the
> above message. I would like to know why I am getting such message and is
it
> safe to run a update query to update the blank field in one record via
Query
> Analyzer. Thanks
> "Aaron [SQL Server MVP]" wrote:
> > > As I am trying to add the value to this field on a particular row
> >
> > How are you "trying to add the value"? An update statement, a stored
> > procedure call, pasting into Enterprise Manager's "Open Table" view, ...
> >
> > --
> > http://www.aspfaq.com/
> > (Reverse address to reply.)
> >
> >
> >|||Thanks for the help Aaron. I appreciate it.
"Aaron [SQL Server MVP]" wrote:
> If your table has a primary key (or a unique way to identify a single row),
> then yes, I would use an UPDATE statement in Query Analyzer. Enterprise
> Manager has its purposes, but data manipulation is not one of them. Please
> have a look through this article: http://www.aspfaq.com/2455
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Jack" <Jack@.discussions.microsoft.com> wrote in message
> news:C2FBA83A-46B0-4F54-85CA-7D829462E75B@.microsoft.com...
> > I was trying to add the blank field value from Enterprise Manager, by
> right
> > clicking and opening the table and choosing all row option and then going
> to
> > the right record and the blank field to fill it up. At this point, I got
> the
> > above message. I would like to know why I am getting such message and is
> it
> > safe to run a update query to update the blank field in one record via
> Query
> > Analyzer. Thanks
> >
> > "Aaron [SQL Server MVP]" wrote:
> >
> > > > As I am trying to add the value to this field on a particular row
> > >
> > > How are you "trying to add the value"? An update statement, a stored
> > > procedure call, pasting into Enterprise Manager's "Open Table" view, ...
> > >
> > > --
> > > http://www.aspfaq.com/
> > > (Reverse address to reply.)
> > >
> > >
> > >
>
>|||Chances are the table does not have a valid PK and is causing the error.
--
Andrew J. Kelly SQL MVP
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:C2FBA83A-46B0-4F54-85CA-7D829462E75B@.microsoft.com...
>I was trying to add the blank field value from Enterprise Manager, by right
> clicking and opening the table and choosing all row option and then going
> to
> the right record and the blank field to fill it up. At this point, I got
> the
> above message. I would like to know why I am getting such message and is
> it
> safe to run a update query to update the blank field in one record via
> Query
> Analyzer. Thanks
> "Aaron [SQL Server MVP]" wrote:
>> > As I am trying to add the value to this field on a particular row
>> How are you "trying to add the value"? An update statement, a stored
>> procedure call, pasting into Enterprise Manager's "Open Table" view, ...
>> --
>> http://www.aspfaq.com/
>> (Reverse address to reply.)
>>
I am dealing with an application where the back-end is SqlServer2000. There
is a master table where one filed is empty that needs to be filled in with
correct value. As I am trying to add the value to this field on a particular
row, I am getting the following message: Transaction cannot start while in
firehose mode. Now I am planning to send a update command to the particular
row to fill in the blank value for the field concerned. However, before I do
that I just want to know, why I am getting the above error. Any help is
appreciated. Thanks.> As I am trying to add the value to this field on a particular row
How are you "trying to add the value"? An update statement, a stored
procedure call, pasting into Enterprise Manager's "Open Table" view, ...
--
http://www.aspfaq.com/
(Reverse address to reply.)|||I was trying to add the blank field value from Enterprise Manager, by right
clicking and opening the table and choosing all row option and then going to
the right record and the blank field to fill it up. At this point, I got the
above message. I would like to know why I am getting such message and is it
safe to run a update query to update the blank field in one record via Query
Analyzer. Thanks
"Aaron [SQL Server MVP]" wrote:
> > As I am trying to add the value to this field on a particular row
> How are you "trying to add the value"? An update statement, a stored
> procedure call, pasting into Enterprise Manager's "Open Table" view, ...
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>|||If your table has a primary key (or a unique way to identify a single row),
then yes, I would use an UPDATE statement in Query Analyzer. Enterprise
Manager has its purposes, but data manipulation is not one of them. Please
have a look through this article: http://www.aspfaq.com/2455
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:C2FBA83A-46B0-4F54-85CA-7D829462E75B@.microsoft.com...
> I was trying to add the blank field value from Enterprise Manager, by
right
> clicking and opening the table and choosing all row option and then going
to
> the right record and the blank field to fill it up. At this point, I got
the
> above message. I would like to know why I am getting such message and is
it
> safe to run a update query to update the blank field in one record via
Query
> Analyzer. Thanks
> "Aaron [SQL Server MVP]" wrote:
> > > As I am trying to add the value to this field on a particular row
> >
> > How are you "trying to add the value"? An update statement, a stored
> > procedure call, pasting into Enterprise Manager's "Open Table" view, ...
> >
> > --
> > http://www.aspfaq.com/
> > (Reverse address to reply.)
> >
> >
> >|||Thanks for the help Aaron. I appreciate it.
"Aaron [SQL Server MVP]" wrote:
> If your table has a primary key (or a unique way to identify a single row),
> then yes, I would use an UPDATE statement in Query Analyzer. Enterprise
> Manager has its purposes, but data manipulation is not one of them. Please
> have a look through this article: http://www.aspfaq.com/2455
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Jack" <Jack@.discussions.microsoft.com> wrote in message
> news:C2FBA83A-46B0-4F54-85CA-7D829462E75B@.microsoft.com...
> > I was trying to add the blank field value from Enterprise Manager, by
> right
> > clicking and opening the table and choosing all row option and then going
> to
> > the right record and the blank field to fill it up. At this point, I got
> the
> > above message. I would like to know why I am getting such message and is
> it
> > safe to run a update query to update the blank field in one record via
> Query
> > Analyzer. Thanks
> >
> > "Aaron [SQL Server MVP]" wrote:
> >
> > > > As I am trying to add the value to this field on a particular row
> > >
> > > How are you "trying to add the value"? An update statement, a stored
> > > procedure call, pasting into Enterprise Manager's "Open Table" view, ...
> > >
> > > --
> > > http://www.aspfaq.com/
> > > (Reverse address to reply.)
> > >
> > >
> > >
>
>|||Chances are the table does not have a valid PK and is causing the error.
--
Andrew J. Kelly SQL MVP
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:C2FBA83A-46B0-4F54-85CA-7D829462E75B@.microsoft.com...
>I was trying to add the blank field value from Enterprise Manager, by right
> clicking and opening the table and choosing all row option and then going
> to
> the right record and the blank field to fill it up. At this point, I got
> the
> above message. I would like to know why I am getting such message and is
> it
> safe to run a update query to update the blank field in one record via
> Query
> Analyzer. Thanks
> "Aaron [SQL Server MVP]" wrote:
>> > As I am trying to add the value to this field on a particular row
>> How are you "trying to add the value"? An update statement, a stored
>> procedure call, pasting into Enterprise Manager's "Open Table" view, ...
>> --
>> http://www.aspfaq.com/
>> (Reverse address to reply.)
>>
Subscribe to:
Posts (Atom)