From administrivia at databaseadvisors.com Tue Jul 3 12:29:37 2012 From: administrivia at databaseadvisors.com (administrivia at databaseadvisors.com) Date: Tue, 3 Jul 2012 18:29:37 +0100 Subject: [dba-SQLServer] Manager Customer Service Message-ID: <4FCCAA15.708070@databaseadvisors.com> We have an excellent opportunity for an apprentice applicant to join a rapidly expanding company. An at home Key Account Manager Position (Ref: 43870-030/4HR) is a great opportunity for stay at home parents or anyone who wants to work in the comfort of their own home. This is a genuine offer and not to be confused with scams! The successful candidate must have the ability to handle calls efficiently whilst maintaining the highest levels of customer service and being courteous. Applicants must have an excellent telephone manner, have a friendly approach, excellent communication skills and be computer literate. You must have the ability to type and talk at the same time to customers, as you will be taking customer details over the phone and inputting data onto company database. Requirements: computer with Internet access, valid email address, good typing skills. If you fit the above description and meet the requirements, please apply to this ad stating your location. You will be processing orders from your computer. How much you earn is up to you. The average is in the region of US$600- US$750.00 per week, depending on whether you work full or part time. If you would like more information, please contact us stating where you are located and our job reference number - 43870-030/4HR. Please only SERIOUS applicants. Our contacts: Jo at careerin-finance.com Thank You! From fuller.artful at gmail.com Sun Jul 15 08:54:03 2012 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sun, 15 Jul 2012 09:54:03 -0400 Subject: [dba-SQLServer] If Exists puzzle Message-ID: I'm trying to check for the existence of a table, and if it does, drop it. I did a search and came up with some code like this: IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') PRINT 'TableName available.' ELSE PRINT 'TableName not available.' This returns the message "Invalid object name: sys.tables So then I reverted to the older syntax: IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = OBJECT_ID(N'[IDS]..[dbo.MyTable')) PRINT 'MyTable exists' ELSE PRINT 'MyTable does not exist' This syntax works but the result is "dbo._Tble_852Import does not exist". Unfortunately, the table does exist. I'm in the right database when running the query, so that's not the problem Any idea what I'm doing wrong? TIA, -- Arthur Cell: 647.710.1314 Prediction is difficult, especially of the future. -- Niels Bohr From rockysmolin at bchacc.com Sun Jul 15 09:03:03 2012 From: rockysmolin at bchacc.com (Rocky Smolin) Date: Sun, 15 Jul 2012 07:03:03 -0700 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: References: Message-ID: <004EA4E303774C3EBB2071028B80A28B@HAL9007> Maybe you could work around the problem by trying to open it with DAO and trap the error if it doesn't exist? Rocky -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Sunday, July 15, 2012 6:54 AM To: Discussion concerning MS SQL Server Subject: [dba-SQLServer] If Exists puzzle I'm trying to check for the existence of a table, and if it does, drop it. I did a search and came up with some code like this: IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') PRINT 'TableName available.' ELSE PRINT 'TableName not available.' This returns the message "Invalid object name: sys.tables So then I reverted to the older syntax: IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = OBJECT_ID(N'[IDS]..[dbo.MyTable')) PRINT 'MyTable exists' ELSE PRINT 'MyTable does not exist' This syntax works but the result is "dbo._Tble_852Import does not exist". Unfortunately, the table does exist. I'm in the right database when running the query, so that's not the problem Any idea what I'm doing wrong? TIA, -- Arthur Cell: 647.710.1314 Prediction is difficult, especially of the future. -- Niels Bohr _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From ssharkins at gmail.com Sun Jul 15 09:18:19 2012 From: ssharkins at gmail.com (Susan Harkins) Date: Sun, 15 Jul 2012 10:18:19 -0400 Subject: [dba-SQLServer] If Exists puzzle References: Message-ID: Wouldn't it just be easier to run a Delete preceded by an On Error? Susan H. > I'm trying to check for the existence of a table, and if it does, drop it. > I did a search and came up with some code like this: > > > IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') > PRINT 'TableName available.' > ELSE > PRINT 'TableName not available.' > > > This returns the message "Invalid object name: sys.tables > > So then I reverted to the older syntax: > > > IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = > OBJECT_ID(N'[IDS]..[dbo.MyTable')) > PRINT 'MyTable exists' > ELSE > PRINT 'MyTable does not exist' > > > This syntax works but the result is "dbo._Tble_852Import does not exist". > Unfortunately, the table does exist. I'm in the right database when > running > the query, so that's not the problem > > Any idea what I'm doing wrong? > TIA, > -- > Arthur > Cell: 647.710.1314 > > Prediction is difficult, especially of the future. > -- Niels Bohr > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > From ab-mi at post3.tele.dk Sun Jul 15 09:28:39 2012 From: ab-mi at post3.tele.dk (Asger Blond) Date: Sun, 15 Jul 2012 16:28:39 +0200 Subject: [dba-SQLServer] If Exists puzzle References: Message-ID: <6E.EA.18979.893D2005@fep44.mail.dk> The name column of sys.tables doesn't include the schema name, i.e. just 'MyTable' not 'dbo.MyTable'. Asger ----- Original meddelelse ----- > Fra: Arthur Fuller > Til: Discussion concerning MS SQL Server > > Dato: S?n, 15. jul 2012 15:54 > Emne: [dba-SQLServer] If Exists puzzle > > I'm trying to check for the existence of a table, and if it does, > drop it. > I did a search and came up with some code like this: > > > IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') > PRINT 'TableName available.' > ELSE > PRINT 'TableName not available.' > > > This returns the message "Invalid object name: sys.tables > > So then I reverted to the older syntax: > > > IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = > OBJECT_ID(N'[IDS]..[dbo.MyTable')) > PRINT 'MyTable exists' > ELSE > PRINT 'MyTable does not exist' > > > This syntax works but the result is "dbo._Tble_852Import does not > exist". > Unfortunately, the table does exist. I'm in the right database when > running > the query, so that's not the problem > > Any idea what I'm doing wrong? > TIA, > -- > Arthur > Cell: 647.710.1314 > > Prediction is difficult, especially of the future. > -- Niels Bohr > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com From fuller.artful at gmail.com Sun Jul 15 09:31:10 2012 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sun, 15 Jul 2012 10:31:10 -0400 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: References: Message-ID: Sorry, I should have pointed out that this is T-SQL code not Access or other. A. On Sun, Jul 15, 2012 at 10:18 AM, Susan Harkins wrote: > Wouldn't it just be easier to run a Delete preceded by an On Error? > > Susan H. > > > I'm trying to check for the existence of a table, and if it does, drop it. >> I did a search and came up with some code like this: >> >> >> IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') >> PRINT 'TableName available.' >> ELSE >> PRINT 'TableName not available.' >> >> >> This returns the message "Invalid object name: sys.tables >> >> So then I reverted to the older syntax: >> >> >> IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = >> OBJECT_ID(N'[IDS]..[dbo.**MyTable')) >> PRINT 'MyTable exists' >> ELSE >> PRINT 'MyTable does not exist' >> >> >> This syntax works but the result is "dbo._Tble_852Import does not exist". >> Unfortunately, the table does exist. I'm in the right database when >> running >> the query, so that's not the problem >> >> Any idea what I'm doing wrong? >> TIA, >> -- >> Arthur >> Cell: 647.710.1314 >> >> Prediction is difficult, especially of the future. >> -- Niels Bohr >> ______________________________**_________________ >> 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@**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 fuller.artful at gmail.com Sun Jul 15 09:33:24 2012 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sun, 15 Jul 2012 10:33:24 -0400 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: References: Message-ID: I don't seem to have the table called sys.tables; hence my reversion to the older syntax. On Sun, Jul 15, 2012 at 10:31 AM, Arthur Fuller wrote: > Sorry, I should have pointed out that this is T-SQL code not Access or > other. > A. > > > From davidmcafee at gmail.com Sun Jul 15 14:13:58 2012 From: davidmcafee at gmail.com (David McAfee) Date: Sun, 15 Jul 2012 12:13:58 -0700 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: References: Message-ID: This is what I use: if (exists (select * from YourDataBaseNameHere.dbo.sysobjects where (name = N'SomeTable') and (type = 'U') and (uid = user_id('dbo')))) PRINT 'Yes' ELSE PRINT 'No' --for #temptables: if (exists (select * from TEMPdb.dbo.sysobjects WHERE (name = N'##tmpBatchUpload') and ( xtype = 'U') and (uid = user_id('dbo')) )) --drop table dbo.SomeTable PRINT 'Yes' ELSE PRINT 'No' --Search all databases for table: Exec sp_MSforeachdb 'Select ''?'' as Dbname, * >From ?.INFORMATION_SCHEMA.Tables where TABLE_NAME like ''YourTableNameHere''' On Sun, Jul 15, 2012 at 6:54 AM, Arthur Fuller wrote: > I'm trying to check for the existence of a table, and if it does, drop it. > I did a search and came up with some code like this: > > > IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') > PRINT 'TableName available.' > ELSE > PRINT 'TableName not available.' > > > This returns the message "Invalid object name: sys.tables > > So then I reverted to the older syntax: > > > IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = > OBJECT_ID(N'[IDS]..[dbo.MyTable')) > PRINT 'MyTable exists' > ELSE > PRINT 'MyTable does not exist' > > > This syntax works but the result is "dbo._Tble_852Import does not exist". > Unfortunately, the table does exist. I'm in the right database when running > the query, so that's not the problem > > Any idea what I'm doing wrong? > TIA, > -- > Arthur > Cell: 647.710.1314 > > Prediction is difficult, especially of the future. > -- Niels Bohr > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fuller.artful at gmail.com Sun Jul 15 15:32:22 2012 From: fuller.artful at gmail.com (Arthur Fuller) Date: Sun, 15 Jul 2012 16:32:22 -0400 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: References: Message-ID: That appears to have worked. Thanks! On Sun, Jul 15, 2012 at 3:13 PM, David McAfee wrote: > This is what I use: > > if (exists (select * > from YourDataBaseNameHere.dbo.sysobjects > where (name = N'SomeTable') and (type = 'U') and (uid = > user_id('dbo')))) > PRINT 'Yes' > ELSE > PRINT 'No' > > --for #temptables: > if (exists (select * from TEMPdb.dbo.sysobjects > WHERE (name = N'##tmpBatchUpload') and > ( xtype = 'U') and > (uid = user_id('dbo')) > )) > --drop table dbo.SomeTable > PRINT 'Yes' > ELSE > PRINT 'No' > > > --Search all databases for table: > Exec sp_MSforeachdb > 'Select ''?'' as Dbname, * > From ?.INFORMATION_SCHEMA.Tables > where TABLE_NAME like ''YourTableNameHere''' > > On Sun, Jul 15, 2012 at 6:54 AM, Arthur Fuller >wrote: > > > I'm trying to check for the existence of a table, and if it does, drop > it. > > I did a search and came up with some code like this: > > > > > > IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') > > PRINT 'TableName available.' > > ELSE > > PRINT 'TableName not available.' > > > > > > This returns the message "Invalid object name: sys.tables > > > > So then I reverted to the older syntax: > > > > > > IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = > > OBJECT_ID(N'[IDS]..[dbo.MyTable')) > > PRINT 'MyTable exists' > > ELSE > > PRINT 'MyTable does not exist' > > > > > > This syntax works but the result is "dbo._Tble_852Import does not exist". > > Unfortunately, the table does exist. I'm in the right database when > running > > the query, so that's not the problem > > > > Any idea what I'm doing wrong? > > TIA, > > -- > > Arthur > > Cell: 647.710.1314 > > > > Prediction is difficult, especially of the future. > > -- Niels Bohr > > _______________________________________________ > > 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 > > -- Arthur Cell: 647.710.1314 Prediction is difficult, especially of the future. -- Niels Bohr From rls at WeBeDb.com Mon Jul 16 08:19:03 2012 From: rls at WeBeDb.com (Robert Stewart) Date: Mon, 16 Jul 2012 08:19:03 -0500 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: References: Message-ID: <26C565A0-BC5A-428D-B5CA-DEB91D794C4D@holly.arvixe.com> Arthur, Is this a temp table? If so, it is not in your database, it is in the tempdb. Another suggestion is to take of the 1 in SELECT 1. A second one is to use sys.All_Objects and filter for the table objects and the table name. See below: SELECT name, type, type_desc FROM sys.all_objects WHERE (type_desc = N'USER_TABLE') AND (name = N'AssetUser') At 09:03 AM 7/15/2012, you wrote: >Date: Sun, 15 Jul 2012 09:54:03 -0400 >From: Arthur Fuller >To: Discussion concerning MS SQL Server > >Subject: [dba-SQLServer] If Exists puzzle >Message-ID: > >Content-Type: text/plain; charset=ISO-8859-1 > >I'm trying to check for the existence of a table, and if it does, drop it. >I did a search and came up with some code like this: > > >IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') >PRINT 'TableName available.' >ELSE >PRINT 'TableName not available.' > > >This returns the message "Invalid object name: sys.tables > >So then I reverted to the older syntax: > > >IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = >OBJECT_ID(N'[IDS]..[dbo.MyTable')) > PRINT 'MyTable exists' >ELSE > PRINT 'MyTable does not exist' > > >This syntax works but the result is "dbo._Tble_852Import does not exist". >Unfortunately, the table does exist. I'm in the right database when running >the query, so that's not the problem > >Any idea what I'm doing wrong? >TIA, >-- >Arthur >Cell: 647.710.1314 > >Prediction is difficult, especially of the future. > -- Niels Bohr Robert L. Stewart www.WeBeDb.com www.DBGUIDesign.com www.RLStewartPhotography.com From fuller.artful at gmail.com Mon Jul 16 08:23:37 2012 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 16 Jul 2012 09:23:37 -0400 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: <26C565A0-BC5A-428D-B5CA-DEB91D794C4D@holly.arvixe.com> References: <26C565A0-BC5A-428D-B5CA-DEB91D794C4D@holly.arvixe.com> Message-ID: Thanks. David McAfee's suggestion works perfectly. Arthur On Mon, Jul 16, 2012 at 9:19 AM, Robert Stewart wrote: > Arthur, > > Is this a temp table? > > If so, it is not in your database, it is in the tempdb. > > Another suggestion is to take of the 1 in SELECT 1. > A second one is to use sys.All_Objects and filter for the table objects > and the table name. > See below: > > SELECT name, type, type_desc > FROM sys.all_objects > WHERE (type_desc = N'USER_TABLE') AND (name = N'AssetUser') > > > From fhtapia at gmail.com Mon Jul 16 09:08:00 2012 From: fhtapia at gmail.com (Francisco Tapia) Date: Mon, 16 Jul 2012 07:08:00 -0700 Subject: [dba-SQLServer] If Exists puzzle In-Reply-To: References: Message-ID: +1 -Francisco On Sun, Jul 15, 2012 at 12:13 PM, David McAfee wrote: > This is what I use: > > if (exists (select * > from YourDataBaseNameHere.dbo.sysobjects > where (name = N'SomeTable') and (type = 'U') and (uid = > user_id('dbo')))) > PRINT 'Yes' > ELSE > PRINT 'No' > > --for #temptables: > if (exists (select * from TEMPdb.dbo.sysobjects > WHERE (name = N'##tmpBatchUpload') and > ( xtype = 'U') and > (uid = user_id('dbo')) > )) > --drop table dbo.SomeTable > PRINT 'Yes' > ELSE > PRINT 'No' > > > --Search all databases for table: > Exec sp_MSforeachdb > 'Select ''?'' as Dbname, * > From ?.INFORMATION_SCHEMA.Tables > where TABLE_NAME like ''YourTableNameHere''' > > On Sun, Jul 15, 2012 at 6:54 AM, Arthur Fuller >wrote: > > > I'm trying to check for the existence of a table, and if it does, drop > it. > > I did a search and came up with some code like this: > > > > > > IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'dbo.MyTable') > > PRINT 'TableName available.' > > ELSE > > PRINT 'TableName not available.' > > > > > > This returns the message "Invalid object name: sys.tables > > > > So then I reverted to the older syntax: > > > > > > IF EXISTS(SELECT * FROM IDS.dbo.sysobjects WHERE ID = > > OBJECT_ID(N'[IDS]..[dbo.MyTable')) > > PRINT 'MyTable exists' > > ELSE > > PRINT 'MyTable does not exist' > > > > > > This syntax works but the result is "dbo._Tble_852Import does not exist". > > Unfortunately, the table does exist. I'm in the right database when > running > > the query, so that's not the problem > > > > Any idea what I'm doing wrong? > > TIA, > > -- > > Arthur > > Cell: 647.710.1314 > > > > Prediction is difficult, especially of the future. > > -- Niels Bohr > > _______________________________________________ > > 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 Jul 25 19:06:09 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 25 Jul 2012 20:06:09 -0400 Subject: [dba-SQLServer] Get a count inside of a stored procedure Message-ID: <501089F1.307@colbyconsulting.com> In a stored procedure I need to get a count of the records in a table where the table name is passed in to the SP. I tried: DECLARE @RecordCnt int SELECT @RecordCnt = Count([Column 0]) FROM @TblName Where @TblName is the passed in table name. This fails telling me that I have to declare a table variable @TblName Is there a simple way to do what I am trying to do? -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it From fhtapia at gmail.com Wed Jul 25 21:05:12 2012 From: fhtapia at gmail.com (Francisco Tapia) Date: Wed, 25 Jul 2012 19:05:12 -0700 Subject: [dba-SQLServer] Get a count inside of a stored procedure In-Reply-To: <501089F1.307@colbyconsulting.com> References: <501089F1.307@colbyconsulting.com> Message-ID: <99740795390462996@unknownmsgid> Try this approach: http://sqlthis.blogspot.com/2011/01/lighting-quick-table-rowcounts-for-your.html?m=1 Sent from my mobile device On Jul 25, 2012, at 5:08 PM, jwcolby wrote: > In a stored procedure I need to get a count of the records in a table where the table name is passed in to the SP. > > I tried: > > DECLARE @RecordCnt int > > SELECT @RecordCnt = Count([Column 0]) FROM @TblName > > Where @TblName is the passed in table name. > > This fails telling me that I have to declare a table variable @TblName > > Is there a simple way to do what I am trying to do? > -- > 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 jwcolby at colbyconsulting.com Wed Jul 25 21:19:01 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 25 Jul 2012 22:19:01 -0400 Subject: [dba-SQLServer] Get a count inside of a stored procedure In-Reply-To: <99740795390462996@unknownmsgid> References: <501089F1.307@colbyconsulting.com> <99740795390462996@unknownmsgid> Message-ID: <5010A915.2090106@colbyconsulting.com> Thanks Francisco. John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 7/25/2012 10:05 PM, Francisco Tapia wrote: > Try this approach: > > http://sqlthis.blogspot.com/2011/01/lighting-quick-table-rowcounts-for-your.html?m=1 > > Sent from my mobile device > > On Jul 25, 2012, at 5:08 PM, jwcolby wrote: > >> In a stored procedure I need to get a count of the records in a table where the table name is passed in to the SP. >> >> I tried: >> >> DECLARE @RecordCnt int >> >> SELECT @RecordCnt = Count([Column 0]) FROM @TblName >> >> Where @TblName is the passed in table name. >> >> This fails telling me that I have to declare a table variable @TblName >> >> Is there a simple way to do what I am trying to do? >> -- >> 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 jwcolby at colbyconsulting.com Thu Jul 26 08:54:01 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 26 Jul 2012 09:54:01 -0400 Subject: [dba-SQLServer] What gives with Null (or the lack thereof) Message-ID: <50114BF9.6030805@colbyconsulting.com> I have two queries: SELECT [EM_Email] ,[EM_EmailDomain] FROM [_DataEmail].[dbo].[tblEmail_Live] WHERE EM_EmailDomain is null GO Returns nothing. SELECT TOP (100) PERCENT COUNT(PK) AS Cnt, EM_EmailDomain FROM dbo.tblEmail_Live GROUP BY EM_EmailDomain ORDER BY Cnt DESC returns null as the top most common EM_EmailDomain Same table, same field, one query says I have lots of null values by count, the other query refuses to show them to me. I'm confused. -- 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 Jul 26 10:11:54 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 26 Jul 2012 11:11:54 -0400 Subject: [dba-SQLServer] What gives with Null (or the lack thereof) In-Reply-To: <50114BF9.6030805@colbyconsulting.com> References: <50114BF9.6030805@colbyconsulting.com> Message-ID: <50115E3A.1090906@colbyconsulting.com> Never mind. I had a string value 'null' in there which is (of course) not NULL. Sigh. John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 7/26/2012 9:54 AM, jwcolby wrote: > I have two queries: > > SELECT [EM_Email] > ,[EM_EmailDomain] > FROM [_DataEmail].[dbo].[tblEmail_Live] > WHERE EM_EmailDomain is null > GO > > Returns nothing. > > SELECT TOP (100) PERCENT COUNT(PK) AS Cnt, EM_EmailDomain > FROM dbo.tblEmail_Live > GROUP BY EM_EmailDomain > ORDER BY Cnt DESC > > returns null as the top most common EM_EmailDomain > > Same table, same field, one query says I have lots of null values by count, the other query refuses > to show them to me. > > I'm confused. > From marklbreen at gmail.com Fri Jul 27 04:01:58 2012 From: marklbreen at gmail.com (Mark Breen) Date: Fri, 27 Jul 2012 10:01:58 +0100 Subject: [dba-SQLServer] What gives with Null (or the lack thereof) In-Reply-To: <50115E3A.1090906@colbyconsulting.com> References: <50114BF9.6030805@colbyconsulting.com> <50115E3A.1090906@colbyconsulting.com> Message-ID: Hello John, You were lucky to find it, those problems can often take hours to find, Mark On 26 July 2012 16:11, jwcolby wrote: > Never mind. I had a string value 'null' in there which is (of course) not > NULL. > > Sigh. > > > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > On 7/26/2012 9:54 AM, jwcolby wrote: > >> I have two queries: >> >> SELECT [EM_Email] >> ,[EM_EmailDomain] >> FROM [_DataEmail].[dbo].[tblEmail_**Live] >> WHERE EM_EmailDomain is null >> GO >> >> Returns nothing. >> >> SELECT TOP (100) PERCENT COUNT(PK) AS Cnt, EM_EmailDomain >> FROM dbo.tblEmail_Live >> GROUP BY EM_EmailDomain >> ORDER BY Cnt DESC >> >> returns null as the top most common EM_EmailDomain >> >> Same table, same field, one query says I have lots of null values by >> count, the other query refuses >> to show them to me. >> >> I'm confused. >> >> > ______________________________**_________________ > dba-SQLServer mailing list > dba-SQLServer@**databaseadvisors.com > http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.**com > > From jwcolby at colbyconsulting.com Fri Jul 27 06:23:48 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 27 Jul 2012 07:23:48 -0400 Subject: [dba-SQLServer] There are uncommitted transactions Message-ID: <50127A44.2090608@colbyconsulting.com> SQL Server appears to be hanging for a batch job. I am wrapping a group of processes in a transaction. It processes dozens of these things then... suddenly it stops. I cannot get it to start again. If i exit SSMS it pops up a message: "there are uncommitted transactions. Do you wish to commit these transactions before closing the window?" I say yes, it performs a commit, and I can go right back in to SSMS and start up this process and it takes off and runs. So what is SSMS doing to commit these "uncommitted transactions"? And can I do that same thing in TSQL? I wrap the transaction group in a Begin Transaction Do stuff Do more stuff Commit What more is there? -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it From fhtapia at gmail.com Fri Jul 27 07:03:07 2012 From: fhtapia at gmail.com (Francisco Tapia) Date: Fri, 27 Jul 2012 05:03:07 -0700 Subject: [dba-SQLServer] There are uncommitted transactions In-Reply-To: <50127A44.2090608@colbyconsulting.com> References: <50127A44.2090608@colbyconsulting.com> Message-ID: <-5843459794279926472@unknownmsgid> I like to name my transactions So when I write it I do it like this: > Begin Tran t1 > Do stuff > Do more stuff If some stuff begin > Commit Tran t1 End Else begin Rollback tran t1 End In this way I know that what I've wrapped up is actually committed (or rolled back when some criteria is not met.) Sent from my mobile device On Jul 27, 2012, at 4:26 AM, jwcolby wrote: > SQL Server appears to be hanging for a batch job. I am wrapping a group of processes in a transaction. It processes dozens of these things then... suddenly it stops. I cannot get it to start again. If i exit SSMS it pops up a message: > > "there are uncommitted transactions. Do you wish to commit these transactions before closing the window?" > > I say yes, it performs a commit, and I can go right back in to SSMS and start up this process and it takes off and runs. > > So what is SSMS doing to commit these "uncommitted transactions"? And can I do that same thing in TSQL? > > I wrap the transaction group in a > > Begin Transaction > Do stuff > Do more stuff > Commit > > What more is there? > > -- > 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 jwcolby at colbyconsulting.com Fri Jul 27 07:35:42 2012 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 27 Jul 2012 08:35:42 -0400 Subject: [dba-SQLServer] There are uncommitted transactions In-Reply-To: <-5843459794279926472@unknownmsgid> References: <50127A44.2090608@colbyconsulting.com> <-5843459794279926472@unknownmsgid> Message-ID: <50128B1E.6090009@colbyconsulting.com> Is Tran an acceptable abbreviation or was that just an aircode thing? John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it On 7/27/2012 8:03 AM, Francisco Tapia wrote: > I like to name my transactions > So when I write it I do it like this: > >> Begin Tran t1 >> Do stuff >> Do more stuff > If some stuff begin >> Commit Tran t1 > End > Else begin > Rollback tran t1 > End > > In this way I know that what I've wrapped up is actually committed (or > rolled back when some criteria is not met.) > > > > Sent from my mobile device > > On Jul 27, 2012, at 4:26 AM, jwcolby wrote: > >> SQL Server appears to be hanging for a batch job. I am wrapping a group of processes in a transaction. It processes dozens of these things then... suddenly it stops. I cannot get it to start again. If i exit SSMS it pops up a message: >> >> "there are uncommitted transactions. Do you wish to commit these transactions before closing the window?" >> >> I say yes, it performs a commit, and I can go right back in to SSMS and start up this process and it takes off and runs. >> >> So what is SSMS doing to commit these "uncommitted transactions"? And can I do that same thing in TSQL? >> >> I wrap the transaction group in a >> >> Begin Transaction >> Do stuff >> Do more stuff >> Commit >> >> What more is there? >> >> -- >> 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 davidmcafee at gmail.com Fri Jul 27 08:48:38 2012 From: davidmcafee at gmail.com (David McAfee) Date: Fri, 27 Jul 2012 06:48:38 -0700 Subject: [dba-SQLServer] There are uncommitted transactions In-Reply-To: <50128B1E.6090009@colbyconsulting.com> References: <50127A44.2090608@colbyconsulting.com> <-5843459794279926472@unknownmsgid> <50128B1E.6090009@colbyconsulting.com> Message-ID: It's acceptable. I also do it like Francisco showed. When i rollback i like to raise an error so the front end knows it was rolled back and your error trapping can catch it and handle it gracefully. Something like: raiserror('somethingHappened',17,1) Sent from my Droid phone. On Jul 27, 2012 5:37 AM, "jwcolby" wrote: > Is Tran an acceptable abbreviation or was that just an aircode thing? > > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > On 7/27/2012 8:03 AM, Francisco Tapia wrote: > >> I like to name my transactions >> So when I write it I do it like this: >> >> Begin Tran t1 >>> Do stuff >>> Do more stuff >>> >> If some stuff begin >> >>> Commit Tran t1 >>> >> End >> Else begin >> Rollback tran t1 >> End >> >> In this way I know that what I've wrapped up is actually committed (or >> rolled back when some criteria is not met.) >> >> >> >> Sent from my mobile device >> >> On Jul 27, 2012, at 4:26 AM, jwcolby wrote: >> >> SQL Server appears to be hanging for a batch job. I am wrapping a group >>> of processes in a transaction. It processes dozens of these things then... >>> suddenly it stops. I cannot get it to start again. If i exit SSMS it pops >>> up a message: >>> >>> "there are uncommitted transactions. Do you wish to commit these >>> transactions before closing the window?" >>> >>> I say yes, it performs a commit, and I can go right back in to SSMS and >>> start up this process and it takes off and runs. >>> >>> So what is SSMS doing to commit these "uncommitted transactions"? And >>> can I do that same thing in TSQL? >>> >>> I wrap the transaction group in a >>> >>> Begin Transaction >>> Do stuff >>> Do more stuff >>> Commit >>> >>> What more is there? >>> >>> -- >>> 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@**databaseadvisors.com >> http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver >> http://www.databaseadvisors.**com >> >> >> > ______________________________**_________________ > dba-SQLServer mailing list > dba-SQLServer@**databaseadvisors.com > http://databaseadvisors.com/**mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.**com > > From fhtapia at gmail.com Fri Jul 27 09:00:03 2012 From: fhtapia at gmail.com (Francisco Tapia) Date: Fri, 27 Jul 2012 07:00:03 -0700 Subject: [dba-SQLServer] There are uncommitted transactions In-Reply-To: References: <50127A44.2090608@colbyconsulting.com> <-5843459794279926472@unknownmsgid> <50128B1E.6090009@colbyconsulting.com> Message-ID: Hey Dav! good call on the raise error, I think the raise error will be even more significant for John who wants to just know if the process succeeded or failed (and if failed for what reason). -Francisco -------------------------- You should follow me on twitter here: http://twitter.com/fhtapia http://bit.ly/sqlthis | http://bit.ly/xcodethis | SQL | XCode and ... On Fri, Jul 27, 2012 at 6:48 AM, David McAfee wrote: > It's acceptable. > > I also do it like Francisco showed. > > When i rollback i like to raise an error so the front end knows it was > rolled back and your error trapping can catch it and handle it gracefully. > > Something like: raiserror('somethingHappened',17,1) > > Sent from my Droid phone. > On Jul 27, 2012 5:37 AM, "jwcolby" wrote: > > > Is Tran an acceptable abbreviation or was that just an aircode thing? > > > > John W. Colby > > Colby Consulting > > > > Reality is what refuses to go away > > when you do not believe in it > > > > On 7/27/2012 8:03 AM, Francisco Tapia wrote: > > > >> I like to name my transactions > >> So when I write it I do it like this: > >> > >> Begin Tran t1 > >>> Do stuff > >>> Do more stuff > >>> > >> If some stuff begin > >> > >>> Commit Tran t1 > >>> > >> End > >> Else begin > >> Rollback tran t1 > >> End > >> > >> In this way I know that what I've wrapped up is actually committed (or > >> rolled back when some criteria is not met.) > >> > >> > >> > >> Sent from my mobile device > >> > >> On Jul 27, 2012, at 4:26 AM, jwcolby > wrote: > >> > >> SQL Server appears to be hanging for a batch job. I am wrapping a > group > >>> of processes in a transaction. It processes dozens of these things > then... > >>> suddenly it stops. I cannot get it to start again. If i exit SSMS it > pops > >>> up a message: > >>> > >>> "there are uncommitted transactions. Do you wish to commit these > >>> transactions before closing the window?" > >>> > >>> I say yes, it performs a commit, and I can go right back in to SSMS and > >>> start up this process and it takes off and runs. > >>> > >>> So what is SSMS doing to commit these "uncommitted transactions"? And > >>> can I do that same thing in TSQL? > >>> > >>> I wrap the transaction group in a > >>> > >>> Begin Transaction > >>> Do stuff > >>> Do more stuff > >>> Commit > >>> > >>> What more is there? > >>> > >>> -- > >>> 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 fuller.artful at gmail.com Mon Jul 30 10:27:27 2012 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 30 Jul 2012 11:27:27 -0400 Subject: [dba-SQLServer] Actually this is about MySQL not SQL Server Message-ID: My best friend and co-author has been very busy extending and enhancing and embellishing the page on our website, called Common MySQL Queries. Let the world know that Peter is the smartest man I've ever met, and his extensions/enhancements/embellishments to this page evince all the proof I (and you) shall need. If you're interested in MySQL, kindly visit http://www.artfulsoftware.com/infotree/queries.php to be enlightened on how to do tough stuff in MySQL. -- Arthur Cell: 647.710.1314 Fuller's Fith Law: Money never arrives at an inopportune moment. From hans.andersen at phulse.com Tue Jul 31 00:36:30 2012 From: hans.andersen at phulse.com (Hans-Christian Andersen) Date: Mon, 30 Jul 2012 22:36:30 -0700 Subject: [dba-SQLServer] Actually this is about MySQL not SQL Server In-Reply-To: References: Message-ID: Hi Arthur, Thanks for sharing the link. I'm going to tweet it, fyi. Hans On 30 July 2012 08:27, Arthur Fuller wrote: > My best friend and co-author has been very busy extending and enhancing and > embellishing the page on our website, called Common MySQL Queries. Let the > world know that Peter is the smartest man I've ever met, and his > extensions/enhancements/embellishments to this page evince all the proof I > (and you) shall need. > > If you're interested in MySQL, kindly visit > http://www.artfulsoftware.com/infotree/queries.php to be enlightened on > how > to do tough stuff in MySQL. > > -- > Arthur > Cell: 647.710.1314 > > Fuller's Fith Law: > > Money never arrives at an inopportune moment. > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > >