From jwcolby at colbyconsulting.com Thu Nov 1 13:22:24 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 01 Nov 2012 14:22:24 -0400 Subject: [dba-SQLServer] SQL Log file usage Message-ID: <5092BDE0.90002@colbyconsulting.com> I attempted to insert 150 million records into a table, from one database to another. The destination table was empty but had a bunch of indexes on it. I ran out of room on the log file disk and the process hung. I ended up stripping off all of the indexes except the PK clustered index and the insert used less than 1/2 of the previous log file size for the insert. Furthermore the build of the indexes as a second step is essentially not using the log file at all. So the whole argument about "which is faster" also needs to include a component about log file usage. I have no idea which would have been faster - with or without the indexes already in place - but in this case at least stripping off the indexes and building them after the fact seems to make the whole process work without a (log file size) hitch. -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it From jlawrenc1 at shaw.ca Thu Nov 1 14:30:15 2012 From: jlawrenc1 at shaw.ca (Jim Lawrence) Date: Thu, 1 Nov 2012 12:30:15 -0700 Subject: [dba-SQLServer] SQL Log file usage In-Reply-To: <5092BDE0.90002@colbyconsulting.com> References: <5092BDE0.90002@colbyconsulting.com> Message-ID: As far as I know, it is always faster, a lot faster, to insert data into tables without indexes or keys. (Knew a system that took a week to insert all the data but removing the keys first and inserting the data took less than 3 hours) Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, November 01, 2012 11:22 AM To: Access Developers discussion and problem solving; Sqlserver-Dba Subject: [dba-SQLServer] SQL Log file usage I attempted to insert 150 million records into a table, from one database to another. The destination table was empty but had a bunch of indexes on it. I ran out of room on the log file disk and the process hung. I ended up stripping off all of the indexes except the PK clustered index and the insert used less than 1/2 of the previous log file size for the insert. Furthermore the build of the indexes as a second step is essentially not using the log file at all. So the whole argument about "which is faster" also needs to include a component about log file usage. I have no idea which would have been faster - with or without the indexes already in place - but in this case at least stripping off the indexes and building them after the fact seems to make the whole process work without a (log file size) hitch. -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From michael at ddisolutions.com.au Thu Nov 1 18:42:37 2012 From: michael at ddisolutions.com.au (Michael Maddison) Date: Fri, 2 Nov 2012 10:42:37 +1100 Subject: [dba-SQLServer] SQL Log file usage References: <5092BDE0.90002@colbyconsulting.com> Message-ID: <99266C61B516644D9727F983FAFAB46511C436@remote.ddisolutions.com.au> Guys, IIRC you can disable indexes before insert and enable after. I don't recall the command but it's there somewhere :-) Cheers Michael M -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Friday, 2 November 2012 6:30 AM To: 'Discussion concerning MS SQL Server' Subject: Re: [dba-SQLServer] SQL Log file usage As far as I know, it is always faster, a lot faster, to insert data into tables without indexes or keys. (Knew a system that took a week to insert all the data but removing the keys first and inserting the data took less than 3 hours) Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, November 01, 2012 11:22 AM To: Access Developers discussion and problem solving; Sqlserver-Dba Subject: [dba-SQLServer] SQL Log file usage I attempted to insert 150 million records into a table, from one database to another. The destination table was empty but had a bunch of indexes on it. I ran out of room on the log file disk and the process hung. I ended up stripping off all of the indexes except the PK clustered index and the insert used less than 1/2 of the previous log file size for the insert. Furthermore the build of the indexes as a second step is essentially not using the log file at all. So the whole argument about "which is faster" also needs to include a component about log file usage. I have no idea which would have been faster - with or without the indexes already in place - but in this case at least stripping off the indexes and building them after the fact seems to make the whole process work without a (log file size) hitch. -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From newsgrps at dalyn.co.nz Sat Nov 3 03:17:20 2012 From: newsgrps at dalyn.co.nz (David Emerson) Date: Sat, 3 Nov 2012 21:17:20 +1300 Subject: [dba-SQLServer] PostgreSQL Conversion to SQL2012 Message-ID: <006801cdb99b$a5704440$f050ccc0$@dalyn.co.nz> I have a PostgreSql database that I am converting to SQL 2012. There is a line like this: SELECT insert_listitem_if_missing('FareBucket', paxBucketId, paxBucketName) FROM dbo.ttmpImportBooking GROUP BY paxBucketId, paxBucketName ORDER BY paxBucketId, paxBucketName The insert_listitem_if_missing function checks to see if an item record is already in a table and inserts it if it is not. It does it for each record in the select statement. When I tried to create a similar scalar valued function I received an error message that I couldn't use an insert in a function. I ended up making the function a stored procedure and using a cursor to loop through each record and call the stored procedure. DECLARE cc3 CURSOR FOR SELECT bkagtAgentNo, agtAgentName, agtagyCode FROM dbo.ttmpTranzImportBooking GROUP BY paxBucketId, paxBucketName ORDER BY paxBucketId, paxBucketName OPEN cc3 FETCH NEXT FROM cc3 INTO @paxBucketId, @paxBucketName WHILE @@fetch_status=0 BEGIN EXEC dbo.spInsertListItemMissingShortValue 'FareBucket', @paxBucketId, @paxBucketName FETCH NEXT FROM cc3 INTO @paxBucketId, @paxBucketName END CLOSE cc3 DEALLOCATE cc3 Is there a simpler way to replicate this? Regards David Emerson Dalyn Software Ltd Wellington, New Zealand From newsgrps at dalyn.co.nz Thu Nov 8 20:09:22 2012 From: newsgrps at dalyn.co.nz (David Emerson) Date: Fri, 9 Nov 2012 15:09:22 +1300 Subject: [dba-SQLServer] Raising Error in Function Message-ID: <000601cdbe1f$3ca23760$b5e6a620$@dalyn.co.nz> I have the following function in SQL 2012: create FUNCTION [dbo].[fnLegStatusToBookingEventStatus] ( @LegStatus varchar(10) ) RETURNS int AS BEGIN DECLARE @BookingEventStatus int SELECT @BookingEventStatus = CASE WHEN @LegStatus = 'ACTV' THEN 0 WHEN @legStatus = 'CANX' OR @LegStatus = 'RFND' THEN 1 ELSE -1 END IF @BookingEventStatus = -1 RAISERROR('No list found with name %s', 16, 1, @LegStatus) RETURN(@BookingEventStatus) END When I try to execute it I get the following error: Invalid use of a side-effecting operator 'RAISERROR' within a function. Is it possible to raise an error within a function? I would like to have some warning if @LegStatus is not one of the items in the Case statement. If I can only use a stored procedure the how can I call it from within a statement such as: SELECT dbo.fnLegStatusToBookingEventStatus(legtostatus) AS Status, scID AS SourceRecordId FROM dbo.ttmpTranzImportBooking Regards David Emerson Dalyn Software Ltd Wellington, New Zealand From ab-mi at post3.tele.dk Wed Nov 14 14:46:09 2012 From: ab-mi at post3.tele.dk (Asger Blond) Date: Wed, 14 Nov 2012 21:46:09 +0100 Subject: [dba-SQLServer] Fragmentation Message-ID: <2BF399FD17294D1983F5311563B88A88@abpc> Hi all, Testing fragmentation and index rebuild, can anyone explain the following: /* Create test table: */ CREATE TABLE Test(ID int IDENTITY(1,1) CONSTRAINT PK_ID PRIMARY KEY CLUSTERED, SomeColumn varchar(50)); GO /*Insert 300 rows with incrementing values for the clustered column:*/ INSERT Test(SomeColumn) VALUES('some value'); GO 300 /* Check the fragmentation:*/ SELECT avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats( DB_ID(),OBJECT_ID('Test'),NULL,NULL,'DETAILED'); GO --> 50 /* Question: Why does these inserts cause fragmentation of the clustered index? */ /* Try index rebuild and check fragmentation again: */ ALTER INDEX PK_ID ON Test REBUILD; GO SELECT avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats(DB_ID(),OBJECT_ID('test'),NULL,NULL,'DETAILED'); GO --> still 50 /* Question: Why does the index rebuild not remove the fragmentation? */ /* Now cause a deliberate fragmentation by adding a new 800 char column and filling with 800 x's for all existing rows: */ ALTER TABLE Test ADD SomeNewColumn char(800) NOT NULL DEFAULT 'x'; GO /* Check fragmentation: */ SELECT avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats(DB_ID(),OBJECT_ID('test'),NULL,NULL,'DETAILED'); GO --> still 50 /* Retry index rebuild and check fragmentation again: */ ALTER INDEX PK_ID ON Test REBUILD; GO SELECT avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats(DB_ID(),OBJECT_ID('test'),NULL,NULL,'DETAILED'); GO --> now 0 /* Question: Why does an index rebuild remove the fragmentation in this case as opposed to the previous case? */ Asger From jwcolby at colbyconsulting.com Thu Nov 15 13:06:06 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 15 Nov 2012 14:06:06 -0500 Subject: [dba-SQLServer] Strange limit Message-ID: <50A53D1E.4080301@colbyconsulting.com> I am running the folliowing query: SELECT Column_Number, Column_Name FROM _DataDB101.dbo.DB101_ConsumerLayout WHERE (Column_Number IN ('241', '54', '64', '132', '191', '186', '133', '63', '139', '185', '129', '151', '201', '147', '127', '113', '261')) OR (Column_Name IN ('145', '141', '187', '52', '122')) Notice that I am asking for about 22 values in an In() clause. SQL Server is cutting it off after the 17th value returned. I never knew there was such a limit though of course there would be some limit. 17 is rather small. -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it From jwcolby at colbyconsulting.com Thu Nov 15 13:22:02 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 15 Nov 2012 14:22:02 -0500 Subject: [dba-SQLServer] Strange limit In-Reply-To: <50A53D1E.4080301@colbyconsulting.com> References: <50A53D1E.4080301@colbyconsulting.com> Message-ID: <50A540DA.2060202@colbyconsulting.com> sorry, the second in() should also be in column_number and is how I got around the limitation. John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 11/15/2012 2:06 PM, jwcolby wrote: > I am running the folliowing query: > > SELECT Column_Number, Column_Name > FROM _DataDB101.dbo.DB101_ConsumerLayout > WHERE (Column_Number IN ('241', '54', '64', '132', '191', '186', '133', '63', '139', '185', > '129', '151', '201', '147', '127', '113', '261')) OR > (Column_Name IN ('145', '141', '187', '52', '122')) > > Notice that I am asking for about 22 values in an In() clause. SQL Server is cutting it off after > the 17th value returned. > > I never knew there was such a limit though of course there would be some limit. 17 is rather small. > From davidmcafee at gmail.com Thu Nov 15 13:27:48 2012 From: davidmcafee at gmail.com (David McAfee) Date: Thu, 15 Nov 2012 11:27:48 -0800 Subject: [dba-SQLServer] Strange limit In-Reply-To: <50A53D1E.4080301@colbyconsulting.com> References: <50A53D1E.4080301@colbyconsulting.com> Message-ID: I don't think so. I run large manual queries like this. I update a table yesterday with several hundred IDs in an in clause. Can you dump the IDs into a temp table or table variable and select from or join to the temp table? On Thu, Nov 15, 2012 at 11:06 AM, jwcolby wrote: > I am running the folliowing query: > > SELECT Column_Number, Column_Name > FROM _DataDB101.dbo.DB101_**ConsumerLayout > WHERE (Column_Number IN ('241', '54', '64', '132', '191', '186', > '133', '63', '139', '185', '129', '151', '201', '147', '127', '113', > '261')) OR > (Column_Name IN ('145', '141', '187', '52', '122')) > > Notice that I am asking for about 22 values in an In() clause. SQL Server > is cutting it off after the 17th value returned. > > I never knew there was such a limit though of course there would be some > limit. 17 is rather small. > > -- > John W. Colby > Colby Consulting > From garykjos at gmail.com Thu Nov 15 13:40:18 2012 From: garykjos at gmail.com (Gary Kjos) Date: Thu, 15 Nov 2012 13:40:18 -0600 Subject: [dba-SQLServer] Strange limit In-Reply-To: References: <50A53D1E.4080301@colbyconsulting.com> Message-ID: This page talks about doing 30K values in an in clause in 2005 or 2008. http://stackoverflow.com/questions/1869753/maximum-size-for-a-sql-server-query-in-clause-is-there-a-better-approach GK On Thu, Nov 15, 2012 at 1:27 PM, David McAfee wrote: > I don't think so. I run large manual queries like this. > > I update a table yesterday with several hundred IDs in an in clause. > > Can you dump the IDs into a temp table or table variable and select from or > join to the temp table? > > On Thu, Nov 15, 2012 at 11:06 AM, jwcolby wrote: > >> I am running the folliowing query: >> >> SELECT Column_Number, Column_Name >> FROM _DataDB101.dbo.DB101_**ConsumerLayout >> WHERE (Column_Number IN ('241', '54', '64', '132', '191', '186', >> '133', '63', '139', '185', '129', '151', '201', '147', '127', '113', >> '261')) OR >> (Column_Name IN ('145', '141', '187', '52', '122')) >> >> Notice that I am asking for about 22 values in an In() clause. SQL Server >> is cutting it off after the 17th value returned. >> >> I never knew there was such a limit though of course there would be some >> limit. 17 is rather small. >> >> -- >> John W. Colby >> Colby Consulting >> > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From stuart at lexacorp.com.pg Thu Nov 15 15:49:59 2012 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Fri, 16 Nov 2012 07:49:59 +1000 Subject: [dba-SQLServer] Strange limit In-Reply-To: <50A540DA.2060202@colbyconsulting.com> References: <50A53D1E.4080301@colbyconsulting.com>, <50A540DA.2060202@colbyconsulting.com> Message-ID: <50A56387.14625.2CEAC79E@stuart.lexacorp.com.pg> Quotes around Column_number values? Don't tell me column Column_number stores char values :-( -- Stuart On 15 Nov 2012 at 14:22, jwcolby wrote: > sorry, the second in() should also be in column_number and is how I got around the limitation. > > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > On 11/15/2012 2:06 PM, jwcolby wrote: > > I am running the folliowing query: > > > > SELECT Column_Number, Column_Name > > FROM _DataDB101.dbo.DB101_ConsumerLayout > > WHERE (Column_Number IN ('241', '54', '64', '132', '191', '186', '133', '63', '139', '185', > > '129', '151', '201', '147', '127', '113', '261')) OR > > (Column_Name IN ('145', '141', '187', '52', '122')) > > > > Notice that I am asking for about 22 values in an In() clause. SQL Server is cutting it off after > > the 17th value returned. > > > > I never knew there was such a limit though of course there would be some limit. 17 is rather small. > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jwcolby at colbyconsulting.com Thu Nov 15 15:52:55 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 15 Nov 2012 16:52:55 -0500 Subject: [dba-SQLServer] Strange limit In-Reply-To: <50A56387.14625.2CEAC79E@stuart.lexacorp.com.pg> References: <50A53D1E.4080301@colbyconsulting.com>, <50A540DA.2060202@colbyconsulting.com> <50A56387.14625.2CEAC79E@stuart.lexacorp.com.pg> Message-ID: <50A56437.8020703@colbyconsulting.com> This came from a spreadsheet which is a file format. Given to me. I created a small table to hold everything. John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 11/15/2012 4:49 PM, Stuart McLachlan wrote: > Quotes around Column_number values? Don't tell me column Column_number stores char > values :-( > From jwcolby at colbyconsulting.com Fri Nov 16 10:58:04 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 16 Nov 2012 11:58:04 -0500 Subject: [dba-SQLServer] Cannot modify a query Message-ID: <50A6709C.4050109@colbyconsulting.com> I have a specific query with the error "cannot find an entry with index 2 on object with ID 41 in database with ID 14. I can open the query in design view, I can run the query and get data, but I cannot modify the query nor can I delete it. It just happens to be a "base query" for a bunch of other queries and I need to modify the query. I can take the SQL statement and save that as a new query and modify that but I cannot do any mod to the base query. So can I manually edit a table somewhere that stores the definition for this query? -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it From fuller.artful at gmail.com Sat Nov 17 08:06:38 2012 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sat, 17 Nov 2012 09:06:38 -0500 Subject: [dba-SQLServer] Cannot modify a query In-Reply-To: <50A6709C.4050109@colbyconsulting.com> References: <50A6709C.4050109@colbyconsulting.com> Message-ID: You've got me on this one, JC. I have never seen that error before. Are you able to rename the query? If so, you could then rebuild it from scratch and all your other queries would still work. On Fri, Nov 16, 2012 at 11:58 AM, jwcolby wrote: > I have a specific query with the error "cannot find an entry with index 2 > on object with ID 41 in database with ID 14. > > I can open the query in design view, I can run the query and get data, but > I cannot modify the query nor can I delete it. It just happens to be a > "base query" for a bunch of other queries and I need to modify the query. > I can take the SQL statement and save that as a new query and modify that > but I cannot do any mod to the base query. > > So can I manually edit a table somewhere that stores the definition for > this query? > -- > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > ______________________________**_________________ > dba-SQLServer mailing list > dba-SQLServer@**databaseadvisors.com > http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.**com > > -- Arthur Cell: 647.710.1314 Prediction is difficult, especially of the future. -- Niels Bohr From fhtapia at gmail.com Wed Nov 28 13:04:23 2012 From: fhtapia at gmail.com (Francisco Tapia) Date: Wed, 28 Nov 2012 11:04:23 -0800 Subject: [dba-SQLServer] Cannot modify a query In-Reply-To: <50A6709C.4050109@colbyconsulting.com> References: <50A6709C.4050109@colbyconsulting.com> Message-ID: did you move on from this one? what version are you on now? How are you "editing" this query? -Francisco -------------------------- You should follow me on twitter here Blogs: SqlThis! | XCodeThis! On Fri, Nov 16, 2012 at 8:58 AM, jwcolby wrote: > I have a specific query with the error "cannot find an entry with index 2 > on object with ID 41 in database with ID 14. > > I can open the query in design view, I can run the query and get data, but > I cannot modify the query nor can I delete it. It just happens to be a > "base query" for a bunch of other queries and I need to modify the query. > I can take the SQL statement and save that as a new query and modify that > but I cannot do any mod to the base query. > > So can I manually edit a table somewhere that stores the definition for > this query? > -- > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > ______________________________**_________________ > dba-SQLServer mailing list > dba-SQLServer@**databaseadvisors.com > http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.**com > > From fhtapia at gmail.com Wed Nov 28 13:19:03 2012 From: fhtapia at gmail.com (Francisco Tapia) Date: Wed, 28 Nov 2012 11:19:03 -0800 Subject: [dba-SQLServer] SQL Log file usage In-Reply-To: <99266C61B516644D9727F983FAFAB46511C436@remote.ddisolutions.com.au> References: <5092BDE0.90002@colbyconsulting.com> <99266C61B516644D9727F983FAFAB46511C436@remote.ddisolutions.com.au> Message-ID: This worked in 2005, so it should work in 2008... ----Diable Index ALTER INDEX [IX_MyIndexName] ON dbo.TableName DISABLE GO ----Enable Index ALTER INDEX [IX_MyIndexName] ON dbo.TableName REBUILD GO -Francisco -------------------------- You should follow me on twitter here Blogs: SqlThis! | XCodeThis! On Thu, Nov 1, 2012 at 4:42 PM, Michael Maddison < michael at ddisolutions.com.au> wrote: > Guys, > > IIRC you can disable indexes before insert and enable after. > I don't recall the command but it's there somewhere :-) > > Cheers > > Michael M > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim > Lawrence > Sent: Friday, 2 November 2012 6:30 AM > To: 'Discussion concerning MS SQL Server' > Subject: Re: [dba-SQLServer] SQL Log file usage > > As far as I know, it is always faster, a lot faster, to insert data into > tables without indexes or keys. (Knew a system that took a week to > insert all the data but removing the keys first and inserting the data > took less than 3 hours) > > Jim > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Thursday, November 01, 2012 11:22 AM > To: Access Developers discussion and problem solving; Sqlserver-Dba > Subject: [dba-SQLServer] SQL Log file usage > > I attempted to insert 150 million records into a table, from one > database to another. The destination table was empty but had a bunch of > indexes on it. I ran out of room on the log file disk and the process > hung. > > I ended up stripping off all of the indexes except the PK clustered > index and the insert used less than 1/2 of the previous log file size > for the insert. Furthermore the build of the indexes as a second step > is essentially not using the log file at all. > > So the whole argument about "which is faster" also needs to include a > component about log file usage. I have no idea which would have been > faster - with or without the indexes already in place - but in this case > at least stripping off the indexes and building them after the fact > seems to make the whole process work without a (log file size) hitch. > > -- > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jwcolby at colbyconsulting.com Wed Nov 28 14:42:07 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 28 Nov 2012 15:42:07 -0500 Subject: [dba-SQLServer] [SPAM] Re: Cannot modify a query In-Reply-To: References: <50A6709C.4050109@colbyconsulting.com> Message-ID: <50B6771F.5070306@colbyconsulting.com> I have not resolved this. The database appears to be corrupt. I can edit and run it but cannot save edits nor delete the query. John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 11/28/2012 2:04 PM, Francisco Tapia wrote: > did you move on from this one? what version are you on now? How are you > "editing" this query? > > > -Francisco > -------------------------- > You should follow me on twitter here > Blogs: SqlThis! | XCodeThis! > > > > > > > On Fri, Nov 16, 2012 at 8:58 AM, jwcolby wrote: > >> I have a specific query with the error "cannot find an entry with index 2 >> on object with ID 41 in database with ID 14. >> >> I can open the query in design view, I can run the query and get data, but >> I cannot modify the query nor can I delete it. It just happens to be a >> "base query" for a bunch of other queries and I need to modify the query. >> I can take the SQL statement and save that as a new query and modify that >> but I cannot do any mod to the base query. >> >> So can I manually edit a table somewhere that stores the definition for >> this query? >> -- >> John W. Colby >> Colby Consulting >> >> Reality is what refuses to go away >> when you do not believe in it >> >> ______________________________**_________________ >> dba-SQLServer mailing list >> dba-SQLServer@**databaseadvisors.com >> http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver >> http://www.databaseadvisors.**com >> >> > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From mwp.reid at qub.ac.uk Wed Nov 28 14:45:06 2012 From: mwp.reid at qub.ac.uk (Martin Reid) Date: Wed, 28 Nov 2012 20:45:06 +0000 Subject: [dba-SQLServer] [SPAM] Re: Cannot modify a query In-Reply-To: <50B6771F.5070306@colbyconsulting.com> References: <50A6709C.4050109@colbyconsulting.com> <50B6771F.5070306@colbyconsulting.com> Message-ID: <9E14437A-C28F-4027-9813-9B2858556148@qub.ac.uk> John This help http://support.microsoft.com/kb/822747 Sent from my iPad On 28 Nov 2012, at 20:43, "jwcolby" > wrote: I have not resolved this. The database appears to be corrupt. I can edit and run it but cannot save edits nor delete the query. John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 11/28/2012 2:04 PM, Francisco Tapia wrote: did you move on from this one? what version are you on now? How are you "editing" this query? -Francisco -------------------------- You should follow me on twitter here Blogs: SqlThis! | XCodeThis! On Fri, Nov 16, 2012 at 8:58 AM, jwcolby >wrote: I have a specific query with the error "cannot find an entry with index 2 on object with ID 41 in database with ID 14. I can open the query in design view, I can run the query and get data, but I cannot modify the query nor can I delete it. It just happens to be a "base query" for a bunch of other queries and I need to modify the query. I can take the SQL statement and save that as a new query and modify that but I cannot do any mod to the base query. So can I manually edit a table somewhere that stores the definition for this query? -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it ______________________________**_________________ dba-SQLServer mailing list dba-SQLServer@**databaseadvisors.com > http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver http://www.databaseadvisors.**com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Wed Nov 28 15:07:58 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 28 Nov 2012 16:07:58 -0500 Subject: [dba-SQLServer] The problem is the query, not the data In-Reply-To: <9E14437A-C28F-4027-9813-9B2858556148@qub.ac.uk> References: <50A6709C.4050109@colbyconsulting.com> <50B6771F.5070306@colbyconsulting.com> <9E14437A-C28F-4027-9813-9B2858556148@qub.ac.uk> Message-ID: <50B67D2E.1060503@colbyconsulting.com> No, I am talking about the query itself, not the data. I tried to add something (a field I think) and it allowed me to do so until I tried to save the changes, and then SQL Server threw an error. Tried to copy the SQL to a new query and save, that worked. Dried to delete the old query, SQL Server threw an error. So I have a query which works (can pull data) but cannot be modified or deleted. John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 11/28/2012 3:45 PM, Martin Reid wrote: > John > > This help > > http://support.microsoft.com/kb/822747 > > > > Sent from my iPad > > On 28 Nov 2012, at 20:43, "jwcolby" > wrote: > > I have not resolved this. The database appears to be corrupt. I can edit and run it but cannot > save edits nor delete the query. > > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > On 11/28/2012 2:04 PM, Francisco Tapia wrote: > did you move on from this one? what version are you on now? How are you > "editing" this query? > > > -Francisco > -------------------------- > You should follow me on twitter here > Blogs: SqlThis! | XCodeThis! > > > > > > > On Fri, Nov 16, 2012 at 8:58 AM, jwcolby >wrote: > > I have a specific query with the error "cannot find an entry with index 2 > on object with ID 41 in database with ID 14. > > I can open the query in design view, I can run the query and get data, but > I cannot modify the query nor can I delete it. It just happens to be a > "base query" for a bunch of other queries and I need to modify the query. > I can take the SQL statement and save that as a new query and modify that > but I cannot do any mod to the base query. > > So can I manually edit a table somewhere that stores the definition for > this query? > -- > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > ______________________________**_________________ > dba-SQLServer mailing list > dba-SQLServer@**databaseadvisors.com > > http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.**com > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jwcolby at colbyconsulting.com Fri Nov 30 11:25:34 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 30 Nov 2012 12:25:34 -0500 Subject: [dba-SQLServer] BCP out fails Message-ID: <50B8EC0E.1030801@colbyconsulting.com> I am trying to BCP out to text files using a stored procedure with passed parameters. I have done this forever however I always just used a view. In order to do that I have to have a view for each file. Yuk. So I am trying to use a SQL statement in variable @SQL. I have assembled a SQL variable which looks like: ALTER PROCEDURE [dbo].[usp_BCP_OneFileSQL] @DBName varchar(50), @OrderName varchar(50), @Selection varchar(50) -- Add the parameters for the stored procedure here AS BEGIN DECLARE @SingleQuote VARCHAR(10) SELECT @SingleQuote = '''' Declare @SQLQuery varchar(8000) SELECT @SQLQuery = 'SELECT PK, EM_Email, FName, EM_IP, EM_Source, Selection FROM dbo.vOrderBase WHERE (Selection = ' + @SingleQuote + @Selection + @SingleQuote + ')' declare @sql varchar(8000) select @sql = 'bcp "'+ @SQLQuery + '" queryout D:\PSM\Orders\PSM\' + @DBName + '\' + @OrderName + '-' + @Selection + '.txt -c -t, -T -SAzul' print @SQL --declare @sql varchar(8000)select @sql = 'bcp [' + @DBName + '].[dbo].[' + @TblName + '] out D:\PSM\Orders\PSM\PSM11275\' + @TblName + '.txt -c -t, -T -SAzul' exec master..xp_cmdshell @sql End The old (commented out) declare for the sql statement does not work any more of course because of parameter changes. The current @SQL evaluates to: bcp "SELECT PK, EM_Email, FName, EM_IP, EM_Source, Selection FROM dbo.vOrderBase WHERE (Selection = 'PSP-01')" queryout D:\PSM\Orders\PSM\PSM11280\PSM11280-PSP-01.txt -c -t, -T -SAzul Which looks good. Any clue what is wrong with what I am doing? I have been doing the "dedicated query" forever and can continue to limp along doing that but using a dynamically constructed SELECT query would make things so much simpler. -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it