From ssharkins at gmail.com Mon Jan 12 15:19:25 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Mon, 12 Jan 2009 16:19:25 -0500 Subject: [dba-SQLServer] copy a database Message-ID: <045001c974fb$73b11c10$2f8601c7@SusanOne> I need a demo database and it would be so easy if I could just copy AdventureWorks to the SAME server and rename it, but I can't seem to do that. I don't have the Copy Wizard either. Any help? In the end, I'll probably just create a new database and populate a few tables for the demo, but seems like too much work -- should be simpler. Susan H. From dwaters at usinternet.com Mon Jan 12 15:25:18 2009 From: dwaters at usinternet.com (Dan Waters) Date: Mon, 12 Jan 2009 15:25:18 -0600 Subject: [dba-SQLServer] copy a database In-Reply-To: <045001c974fb$73b11c10$2f8601c7@SusanOne> References: <045001c974fb$73b11c10$2f8601c7@SusanOne> Message-ID: <371E8EAC7A80448194F3E2448C36FC90@danwaters> There is a method called Detach and Reattach. It's in SS Help. Dan -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Monday, January 12, 2009 3:19 PM To: SQLList Subject: [dba-SQLServer] copy a database I need a demo database and it would be so easy if I could just copy AdventureWorks to the SAME server and rename it, but I can't seem to do that. I don't have the Copy Wizard either. Any help? In the end, I'll probably just create a new database and populate a few tables for the demo, but seems like too much work -- should be simpler. Susan H. _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From kens.programming at verizon.net Mon Jan 12 15:27:46 2009 From: kens.programming at verizon.net (kens.programming) Date: Mon, 12 Jan 2009 13:27:46 -0800 Subject: [dba-SQLServer] copy a database In-Reply-To: <045001c974fb$73b11c10$2f8601c7@SusanOne> Message-ID: <7F3274C4023B4578BE833658E893BC9B@Stoker.com> Susan, When I want a copy of an existing database, I just use the backup of the existing database and restore it under a different name. I do this all the time. Ken -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Monday, January 12, 2009 1:19 PM To: SQLList Subject: [dba-SQLServer] copy a database I need a demo database and it would be so easy if I could just copy AdventureWorks to the SAME server and rename it, but I can't seem to do that. I don't have the Copy Wizard either. Any help? In the end, I'll probably just create a new database and populate a few tables for the demo, but seems like too much work -- should be simpler. Susan H. _______________________________________________ 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 Mon Jan 12 15:35:01 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Mon, 12 Jan 2009 16:35:01 -0500 Subject: [dba-SQLServer] copy a database References: <7F3274C4023B4578BE833658E893BC9B@Stoker.com> Message-ID: <04bd01c974fd$a2cd6f10$2f8601c7@SusanOne> Well, that sounds easy enough -- I knew there had to be an easy solution and that I was just making it too hard. Thanks! Susan H. > Susan, > > When I want a copy of an existing database, I just use the backup of the > existing database and restore it under a different name. I do this all > the > time. > > Ken > > -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan > Harkins > Sent: Monday, January 12, 2009 1:19 PM > To: SQLList > Subject: [dba-SQLServer] copy a database > > I need a demo database and it would be so easy if I could just copy > AdventureWorks to the SAME server and rename it, but I can't seem to do > that. I don't have the Copy Wizard either. > > Any help? > > In the end, I'll probably just create a new database and populate a few > tables for the demo, but seems like too much work -- should be simpler. > > Susan H. > > _______________________________________________ > 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 ssharkins at gmail.com Tue Jan 13 11:03:54 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 12:03:54 -0500 Subject: [dba-SQLServer] ?s on sp_MSForEachTable Message-ID: <099901c975a0$ec382750$2f8601c7@SusanOne> I ran the following statement against a copy of AdventureWorks, expecting to see some constraint errors: EXEC sp_MSForEachTable 'DELETE FROM ?' Instead, the command was completely successfully -- by message, but of course, no data was deleted, which is what the statement should do -- delete all the records from every table in the database. Of course, I didn't expect it to work because of the constraints, but I did expect to see some kind of error message. It's an undocumented sp and despite my efforts to figure this out, I'm not finding any help. I've found a lot of information on the different arguments and how it's supposed to run, but answers to the above question -- why not error message -- can't find that sort of information. Is anyone familiar with this sp? Susan H. From ssharkins at gmail.com Tue Jan 13 13:23:40 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 14:23:40 -0500 Subject: [dba-SQLServer] executing system stored procedure Message-ID: <0ab901c975b4$723eef60$2f8601c7@SusanOne> I've had this problem before but I don't recall the solution. USE database EXEC sys.sp_MSForEachTable command says it can't find the stored procedure -- I remember I had this problem once before, but I don't remember why. Any help? When I run it against master, I get a command successfully completed, not a "can't find" message, so it must be there. Susan H. From ssharkins at gmail.com Tue Jan 13 14:20:44 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 15:20:44 -0500 Subject: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) Message-ID: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> Was looking for EXEC master..sp_MSForEachTable Now, if I could just get it to work -- system finds the sp, but it doesn't work as expected. Susan H. > USE database > EXEC sys.sp_MSForEachTable command > > says it can't find the stored procedure -- I remember I had this problem > once before, but I don't remember why. Any help? When I run it against > master, I get a command successfully completed, not a "can't find" > message, so it must be there. > > Susan H. From mwp.reid at qub.ac.uk Tue Jan 13 14:24:28 2009 From: mwp.reid at qub.ac.uk (Martin Reid) Date: Tue, 13 Jan 2009 20:24:28 +0000 Subject: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) In-Reply-To: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> Message-ID: Try this Just lifted it of the web use pubs go create table #rowcount (tablename varchar(128), rowcnt int) exec sp_MSforeachtable 'insert into #rowcount select ''?'', count(*) from ?' select top 5 * from #rowcount order by tablename drop table #rowcount Martin Martin WP Reid Information Services Queen's University Riddel Hall 185 Stranmillis Road Belfast BT9 5EE Tel : 02890974465 Email : mwp.reid at qub.ac.uk ________________________________________ From: dba-sqlserver-bounces at databaseadvisors.com [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins [ssharkins at gmail.com] Sent: 13 January 2009 20:20 To: SQLList Subject: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) Was looking for EXEC master..sp_MSForEachTable Now, if I could just get it to work -- system finds the sp, but it doesn't work as expected. Susan H. > USE database > EXEC sys.sp_MSForEachTable command > > says it can't find the stored procedure -- I remember I had this problem > once before, but I don't remember why. Any help? When I run it against > master, I get a command successfully completed, not a "can't find" > message, so it must be there. > > Susan H. _______________________________________________ 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 Tue Jan 13 14:40:37 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 15:40:37 -0500 Subject: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> Message-ID: <0b6d01c975bf$329c7ed0$2f8601c7@SusanOne> Okay -- now that's just plain weird -- went back to the traditional sys.sp syntax, and it works -- that's just odd. I'm sure some typo's to blame, but that's frustrating as I tried the simplest of things and couldn't get anything. Susan H. > Try this > > Just lifted it of the web > > use pubs > go > create table #rowcount (tablename varchar(128), rowcnt int) > exec sp_MSforeachtable > 'insert into #rowcount select ''?'', count(*) from ?' > select top 5 * from #rowcount > order by tablename > drop table #rowcount > > > > > > Martin > > > Martin WP Reid > Information Services > Queen's University > Riddel Hall > 185 Stranmillis Road > Belfast > BT9 5EE > Tel : 02890974465 > Email : mwp.reid at qub.ac.uk > ________________________________________ > From: dba-sqlserver-bounces at databaseadvisors.com > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > [ssharkins at gmail.com] > Sent: 13 January 2009 20:20 > To: SQLList > Subject: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) > > Was looking for > > EXEC master..sp_MSForEachTable > > Now, if I could just get it to work -- system finds the sp, but it doesn't > work as expected. > > Susan H. > > >> USE database >> EXEC sys.sp_MSForEachTable command >> >> says it can't find the stored procedure -- I remember I had this problem >> once before, but I don't remember why. Any help? When I run it against >> master, I get a command successfully completed, not a "can't find" >> message, so it must be there. >> >> Susan H. > > _______________________________________________ > 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 ssharkins at gmail.com Tue Jan 13 14:38:20 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 15:38:20 -0500 Subject: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> Message-ID: <0b6c01c975bf$31fa7270$2f8601c7@SusanOne> I've tried several examples now -- they run, but they don't actually return anything -- this one creates the table, but doesn't fill it. Susan H. > Try this > > Just lifted it of the web > > use pubs > go > create table #rowcount (tablename varchar(128), rowcnt int) > exec sp_MSforeachtable > 'insert into #rowcount select ''?'', count(*) from ?' > select top 5 * from #rowcount > order by tablename > drop table #rowcount From mwp.reid at qub.ac.uk Tue Jan 13 14:50:09 2009 From: mwp.reid at qub.ac.uk (Martin Reid) Date: Tue, 13 Jan 2009 20:50:09 +0000 Subject: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) In-Reply-To: <0b6c01c975bf$31fa7270$2f8601c7@SusanOne> References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> , <0b6c01c975bf$31fa7270$2f8601c7@SusanOne> Message-ID: Susan I ran it just there and it worked fine here I changed the database to a copy I have here and it worked fine. [dbo].[Customers] 29 [dbo].[Employee Privileges] 1 [dbo].[Employees] 9 [dbo].[Inventory Transaction Types] 4 [dbo].[Inventory Transactions] 102 use NWind go create table #rowcount (tablename varchar(128), rowcnt int) exec sp_MSforeachtable 'insert into #rowcount select ''?'', count(*) from ?' select top 5 * from #rowcount order by tablename drop table #rowcount Martin Martin WP Reid Information Services Queen's University Riddel Hall 185 Stranmillis Road Belfast BT9 5EE Tel : 02890974465 Email : mwp.reid at qub.ac.uk ________________________________________ From: dba-sqlserver-bounces at databaseadvisors.com [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins [ssharkins at gmail.com] Sent: 13 January 2009 20:38 To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored procedure) I've tried several examples now -- they run, but they don't actually return anything -- this one creates the table, but doesn't fill it. Susan H. > Try this > > Just lifted it of the web > > use pubs > go > create table #rowcount (tablename varchar(128), rowcnt int) > exec sp_MSforeachtable > 'insert into #rowcount select ''?'', count(*) from ?' > select top 5 * from #rowcount > order by tablename > drop table #rowcount _______________________________________________ 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 Tue Jan 13 15:03:23 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 16:03:23 -0500 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne>, <0b6c01c975bf$31fa7270$2f8601c7@SusanOne> Message-ID: <0bac01c975c2$61682450$2f8601c7@SusanOne> Okay, a little more experimenting and here's what's interesting. Mystery #1: When running against AdventureWorks, I have to use master..sp_ syntax, but others recognize sys.sp_ syntax. Mystery #2: Even when using master..sp_ against AdventureWorks, it recognizes the sp, but doesn't actually run it -- I get a message that it's been successfully completed, but it hasn't actually done a thing. Susan H. ----- Original Message ----- From: "Martin Reid" To: "Discussion concerning MS SQL Server" Sent: Tuesday, January 13, 2009 3:50 PM Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) > Susan > > I ran it just there and it worked fine here I changed the database to a > copy I have here and it worked fine. > > [dbo].[Customers] 29 > [dbo].[Employee Privileges] 1 > [dbo].[Employees] 9 > [dbo].[Inventory Transaction Types] 4 > [dbo].[Inventory Transactions] 102 > > use NWind > go > create table #rowcount (tablename varchar(128), rowcnt int) > exec sp_MSforeachtable > 'insert into #rowcount select ''?'', count(*) from ?' > select top 5 * from #rowcount > order by tablename > drop table #rowcount > > > Martin > > > Martin WP Reid > Information Services > Queen's University > Riddel Hall > 185 Stranmillis Road > Belfast > BT9 5EE > Tel : 02890974465 > Email : mwp.reid at qub.ac.uk > ________________________________________ > From: dba-sqlserver-bounces at databaseadvisors.com > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > [ssharkins at gmail.com] > Sent: 13 January 2009 20:38 > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored > procedure) > > I've tried several examples now -- they run, but they don't actually > return > anything -- this one creates the table, but doesn't fill it. > > Susan H. > > >> Try this >> >> Just lifted it of the web >> >> use pubs >> go >> create table #rowcount (tablename varchar(128), rowcnt int) >> exec sp_MSforeachtable >> 'insert into #rowcount select ''?'', count(*) from ?' >> select top 5 * from #rowcount >> order by tablename >> drop table #rowcount > > _______________________________________________ > 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 mwp.reid at qub.ac.uk Tue Jan 13 15:05:34 2009 From: mwp.reid at qub.ac.uk (Martin Reid) Date: Tue, 13 Jan 2009 21:05:34 +0000 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) In-Reply-To: <0bac01c975c2$61682450$2f8601c7@SusanOne> References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne>, <0b6c01c975bf$31fa7270$2f8601c7@SusanOne> , <0bac01c975c2$61682450$2f8601c7@SusanOne> Message-ID: Are you clicking the results tab? Martin Martin WP Reid Information Services Queen's University Riddel Hall 185 Stranmillis Road Belfast BT9 5EE Tel : 02890974465 Email : mwp.reid at qub.ac.uk ________________________________________ From: dba-sqlserver-bounces at databaseadvisors.com [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins [ssharkins at gmail.com] Sent: 13 January 2009 21:03 To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) Okay, a little more experimenting and here's what's interesting. Mystery #1: When running against AdventureWorks, I have to use master..sp_ syntax, but others recognize sys.sp_ syntax. Mystery #2: Even when using master..sp_ against AdventureWorks, it recognizes the sp, but doesn't actually run it -- I get a message that it's been successfully completed, but it hasn't actually done a thing. Susan H. ----- Original Message ----- From: "Martin Reid" To: "Discussion concerning MS SQL Server" Sent: Tuesday, January 13, 2009 3:50 PM Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) > Susan > > I ran it just there and it worked fine here I changed the database to a > copy I have here and it worked fine. > > [dbo].[Customers] 29 > [dbo].[Employee Privileges] 1 > [dbo].[Employees] 9 > [dbo].[Inventory Transaction Types] 4 > [dbo].[Inventory Transactions] 102 > > use NWind > go > create table #rowcount (tablename varchar(128), rowcnt int) > exec sp_MSforeachtable > 'insert into #rowcount select ''?'', count(*) from ?' > select top 5 * from #rowcount > order by tablename > drop table #rowcount > > > Martin > > > Martin WP Reid > Information Services > Queen's University > Riddel Hall > 185 Stranmillis Road > Belfast > BT9 5EE > Tel : 02890974465 > Email : mwp.reid at qub.ac.uk > ________________________________________ > From: dba-sqlserver-bounces at databaseadvisors.com > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > [ssharkins at gmail.com] > Sent: 13 January 2009 20:38 > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored > procedure) > > I've tried several examples now -- they run, but they don't actually > return > anything -- this one creates the table, but doesn't fill it. > > Susan H. > > >> Try this >> >> Just lifted it of the web >> >> use pubs >> go >> create table #rowcount (tablename varchar(128), rowcnt int) >> exec sp_MSforeachtable >> 'insert into #rowcount select ''?'', count(*) from ?' >> select top 5 * from #rowcount >> order by tablename >> drop table #rowcount > > _______________________________________________ > 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 ssharkins at gmail.com Tue Jan 13 15:11:39 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 16:11:39 -0500 Subject: [dba-SQLServer] Fw: NEVERMIND (Fw: executing systemstored procedure) Message-ID: <0bdf01c975c3$87bb95a0$2f8601c7@SusanOne> Martin, my guess is this is just about AdventureWorks -- since it's downloadable and doesn't actually come with SQL Server, my guess is you have to explicitly specify the path to the system stored procedure. However, that doesn't explain why the following doesn't work, regardless of the syntax: EXEC sys.sp_MSForEachTable 'DELETE FROM ?' That would delete all the records in any table without constraints to another table, but it doesn't. The message says it does, but it doesn't. Since other examples work, I can only guess that I'm expecting the wrong result. Susan H. > Okay, a little more experimenting and here's what's interesting. > > Mystery #1: When running against AdventureWorks, I have to use master..sp_ > syntax, but others recognize sys.sp_ syntax. > Mystery #2: Even when using master..sp_ against AdventureWorks, it > recognizes the sp, but doesn't actually run it -- I get a message that > it's been successfully completed, but it hasn't actually done a thing. > > Susan H. > > > > ----- Original Message ----- > From: "Martin Reid" > To: "Discussion concerning MS SQL Server" > > Sent: Tuesday, January 13, 2009 3:50 PM > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > procedure) > > >> Susan >> >> I ran it just there and it worked fine here I changed the database to a >> copy I have here and it worked fine. >> >> [dbo].[Customers] 29 >> [dbo].[Employee Privileges] 1 >> [dbo].[Employees] 9 >> [dbo].[Inventory Transaction Types] 4 >> [dbo].[Inventory Transactions] 102 >> >> use NWind >> go >> create table #rowcount (tablename varchar(128), rowcnt int) >> exec sp_MSforeachtable >> 'insert into #rowcount select ''?'', count(*) from ?' >> select top 5 * from #rowcount >> order by tablename >> drop table #rowcount >> >> >> Martin >> >> >> Martin WP Reid >> Information Services >> Queen's University >> Riddel Hall >> 185 Stranmillis Road >> Belfast >> BT9 5EE >> Tel : 02890974465 >> Email : mwp.reid at qub.ac.uk >> ________________________________________ >> From: dba-sqlserver-bounces at databaseadvisors.com >> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins >> [ssharkins at gmail.com] >> Sent: 13 January 2009 20:38 >> To: Discussion concerning MS SQL Server >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored >> procedure) >> >> I've tried several examples now -- they run, but they don't actually >> return >> anything -- this one creates the table, but doesn't fill it. >> >> Susan H. >> >> >>> Try this >>> >>> Just lifted it of the web >>> >>> use pubs >>> go >>> create table #rowcount (tablename varchar(128), rowcnt int) >>> exec sp_MSforeachtable >>> 'insert into #rowcount select ''?'', count(*) from ?' >>> select top 5 * from #rowcount >>> order by tablename >>> drop table #rowcount >> >> _______________________________________________ >> 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 ssharkins at gmail.com Tue Jan 13 15:12:38 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 16:12:38 -0500 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne>, <0b6c01c975bf$31fa7270$2f8601c7@SusanOne>, <0bac01c975c2$61682450$2f8601c7@SusanOne> Message-ID: <0be401c975c3$ab374b50$2f8601c7@SusanOne> Most examples work -- the DELETE FROM ? that I've been trying doesn't return a result of course, just the Message tab that it's been completed successfully. Susan H. > Are you clicking the results tab? > > Martin > > > Martin WP Reid > Information Services > Queen's University > Riddel Hall > 185 Stranmillis Road > Belfast > BT9 5EE > Tel : 02890974465 > Email : mwp.reid at qub.ac.uk > ________________________________________ > From: dba-sqlserver-bounces at databaseadvisors.com > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > [ssharkins at gmail.com] > Sent: 13 January 2009 21:03 > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > procedure) > > Okay, a little more experimenting and here's what's interesting. > > Mystery #1: When running against AdventureWorks, I have to use master..sp_ > syntax, but others recognize sys.sp_ syntax. > Mystery #2: Even when using master..sp_ against AdventureWorks, it > recognizes the sp, but doesn't actually run it -- I get a message that > it's > been successfully completed, but it hasn't actually done a thing. > > Susan H. > > > > ----- Original Message ----- > From: "Martin Reid" > To: "Discussion concerning MS SQL Server" > > Sent: Tuesday, January 13, 2009 3:50 PM > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > procedure) > > >> Susan >> >> I ran it just there and it worked fine here I changed the database to a >> copy I have here and it worked fine. >> >> [dbo].[Customers] 29 >> [dbo].[Employee Privileges] 1 >> [dbo].[Employees] 9 >> [dbo].[Inventory Transaction Types] 4 >> [dbo].[Inventory Transactions] 102 >> >> use NWind >> go >> create table #rowcount (tablename varchar(128), rowcnt int) >> exec sp_MSforeachtable >> 'insert into #rowcount select ''?'', count(*) from ?' >> select top 5 * from #rowcount >> order by tablename >> drop table #rowcount >> >> >> Martin >> >> >> Martin WP Reid >> Information Services >> Queen's University >> Riddel Hall >> 185 Stranmillis Road >> Belfast >> BT9 5EE >> Tel : 02890974465 >> Email : mwp.reid at qub.ac.uk >> ________________________________________ >> From: dba-sqlserver-bounces at databaseadvisors.com >> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins >> [ssharkins at gmail.com] >> Sent: 13 January 2009 20:38 >> To: Discussion concerning MS SQL Server >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored >> procedure) >> >> I've tried several examples now -- they run, but they don't actually >> return >> anything -- this one creates the table, but doesn't fill it. >> >> Susan H. >> >> >>> Try this >>> >>> Just lifted it of the web >>> >>> use pubs >>> go >>> create table #rowcount (tablename varchar(128), rowcnt int) >>> exec sp_MSforeachtable >>> 'insert into #rowcount select ''?'', count(*) from ?' >>> select top 5 * from #rowcount >>> order by tablename >>> drop table #rowcount >> >> _______________________________________________ >> 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 > _______________________________________________ > 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 Tue Jan 13 15:16:54 2009 From: mwp.reid at qub.ac.uk (Martin Reid) Date: Tue, 13 Jan 2009 21:16:54 +0000 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) In-Reply-To: <0be401c975c3$ab374b50$2f8601c7@SusanOne> References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne>, <0b6c01c975bf$31fa7270$2f8601c7@SusanOne>, <0bac01c975c2$61682450$2f8601c7@SusanOne> , <0be401c975c3$ab374b50$2f8601c7@SusanOne> Message-ID: Susan Sorry I am in the middle of AR on the new book. If you need this working I can check it in the morning in work on another server with Adventure works installed. Can spend a while on it then. Martin Martin WP Reid Information Services Queen's University Riddel Hall 185 Stranmillis Road Belfast BT9 5EE Tel : 02890974465 Email : mwp.reid at qub.ac.uk ________________________________________ From: dba-sqlserver-bounces at databaseadvisors.com [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins [ssharkins at gmail.com] Sent: 13 January 2009 21:12 To: Discussion concerning MS SQL Server Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) Most examples work -- the DELETE FROM ? that I've been trying doesn't return a result of course, just the Message tab that it's been completed successfully. Susan H. > Are you clicking the results tab? > > Martin > > > Martin WP Reid > Information Services > Queen's University > Riddel Hall > 185 Stranmillis Road > Belfast > BT9 5EE > Tel : 02890974465 > Email : mwp.reid at qub.ac.uk > ________________________________________ > From: dba-sqlserver-bounces at databaseadvisors.com > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > [ssharkins at gmail.com] > Sent: 13 January 2009 21:03 > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > procedure) > > Okay, a little more experimenting and here's what's interesting. > > Mystery #1: When running against AdventureWorks, I have to use master..sp_ > syntax, but others recognize sys.sp_ syntax. > Mystery #2: Even when using master..sp_ against AdventureWorks, it > recognizes the sp, but doesn't actually run it -- I get a message that > it's > been successfully completed, but it hasn't actually done a thing. > > Susan H. > > > > ----- Original Message ----- > From: "Martin Reid" > To: "Discussion concerning MS SQL Server" > > Sent: Tuesday, January 13, 2009 3:50 PM > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > procedure) > > >> Susan >> >> I ran it just there and it worked fine here I changed the database to a >> copy I have here and it worked fine. >> >> [dbo].[Customers] 29 >> [dbo].[Employee Privileges] 1 >> [dbo].[Employees] 9 >> [dbo].[Inventory Transaction Types] 4 >> [dbo].[Inventory Transactions] 102 >> >> use NWind >> go >> create table #rowcount (tablename varchar(128), rowcnt int) >> exec sp_MSforeachtable >> 'insert into #rowcount select ''?'', count(*) from ?' >> select top 5 * from #rowcount >> order by tablename >> drop table #rowcount >> >> >> Martin >> >> >> Martin WP Reid >> Information Services >> Queen's University >> Riddel Hall >> 185 Stranmillis Road >> Belfast >> BT9 5EE >> Tel : 02890974465 >> Email : mwp.reid at qub.ac.uk >> ________________________________________ >> From: dba-sqlserver-bounces at databaseadvisors.com >> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins >> [ssharkins at gmail.com] >> Sent: 13 January 2009 20:38 >> To: Discussion concerning MS SQL Server >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored >> procedure) >> >> I've tried several examples now -- they run, but they don't actually >> return >> anything -- this one creates the table, but doesn't fill it. >> >> Susan H. >> >> >>> Try this >>> >>> Just lifted it of the web >>> >>> use pubs >>> go >>> create table #rowcount (tablename varchar(128), rowcnt int) >>> exec sp_MSforeachtable >>> 'insert into #rowcount select ''?'', count(*) from ?' >>> select top 5 * from #rowcount >>> order by tablename >>> drop table #rowcount >> >> _______________________________________________ >> 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 > _______________________________________________ > 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 ssharkins at gmail.com Tue Jan 13 15:23:42 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Tue, 13 Jan 2009 16:23:42 -0500 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne>, <0b6c01c975bf$31fa7270$2f8601c7@SusanOne>, <0bac01c975c2$61682450$2f8601c7@SusanOne>, <0be401c975c3$ab374b50$2f8601c7@SusanOne> Message-ID: <0bf401c975c5$36f8ec60$2f8601c7@SusanOne> Don't worry about it Martin -- it's my problem -- I'm sure I'm just expecting the wrong thing. Susan H. > Susan > > Sorry I am in the middle of AR on the new book. If you need this working I > can check it in the morning in work on another server with Adventure works > installed. Can spend a while on it then. > > Martin > > > Martin WP Reid > Information Services > Queen's University > Riddel Hall > 185 Stranmillis Road > Belfast > BT9 5EE > Tel : 02890974465 > Email : mwp.reid at qub.ac.uk > ________________________________________ > From: dba-sqlserver-bounces at databaseadvisors.com > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > [ssharkins at gmail.com] > Sent: 13 January 2009 21:12 > To: Discussion concerning MS SQL Server > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > procedure) > > Most examples work -- the DELETE FROM ? that I've been trying doesn't > return > a result of course, just the Message tab that it's been completed > successfully. > > Susan H. > > >> Are you clicking the results tab? >> >> Martin >> >> >> Martin WP Reid >> Information Services >> Queen's University >> Riddel Hall >> 185 Stranmillis Road >> Belfast >> BT9 5EE >> Tel : 02890974465 >> Email : mwp.reid at qub.ac.uk >> ________________________________________ >> From: dba-sqlserver-bounces at databaseadvisors.com >> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins >> [ssharkins at gmail.com] >> Sent: 13 January 2009 21:03 >> To: Discussion concerning MS SQL Server >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored >> procedure) >> >> Okay, a little more experimenting and here's what's interesting. >> >> Mystery #1: When running against AdventureWorks, I have to use >> master..sp_ >> syntax, but others recognize sys.sp_ syntax. >> Mystery #2: Even when using master..sp_ against AdventureWorks, it >> recognizes the sp, but doesn't actually run it -- I get a message that >> it's >> been successfully completed, but it hasn't actually done a thing. >> >> Susan H. >> >> >> >> ----- Original Message ----- >> From: "Martin Reid" >> To: "Discussion concerning MS SQL Server" >> >> Sent: Tuesday, January 13, 2009 3:50 PM >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored >> procedure) >> >> >>> Susan >>> >>> I ran it just there and it worked fine here I changed the database to a >>> copy I have here and it worked fine. >>> >>> [dbo].[Customers] 29 >>> [dbo].[Employee Privileges] 1 >>> [dbo].[Employees] 9 >>> [dbo].[Inventory Transaction Types] 4 >>> [dbo].[Inventory Transactions] 102 >>> >>> use NWind >>> go >>> create table #rowcount (tablename varchar(128), rowcnt int) >>> exec sp_MSforeachtable >>> 'insert into #rowcount select ''?'', count(*) from ?' >>> select top 5 * from #rowcount >>> order by tablename >>> drop table #rowcount >>> >>> >>> Martin >>> >>> >>> Martin WP Reid >>> Information Services >>> Queen's University >>> Riddel Hall >>> 185 Stranmillis Road >>> Belfast >>> BT9 5EE >>> Tel : 02890974465 >>> Email : mwp.reid at qub.ac.uk >>> ________________________________________ >>> From: dba-sqlserver-bounces at databaseadvisors.com >>> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins >>> [ssharkins at gmail.com] >>> Sent: 13 January 2009 20:38 >>> To: Discussion concerning MS SQL Server >>> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored >>> procedure) >>> >>> I've tried several examples now -- they run, but they don't actually >>> return >>> anything -- this one creates the table, but doesn't fill it. >>> >>> Susan H. >>> >>> >>>> Try this >>>> >>>> Just lifted it of the web >>>> >>>> use pubs >>>> go >>>> create table #rowcount (tablename varchar(128), rowcnt int) >>>> exec sp_MSforeachtable >>>> 'insert into #rowcount select ''?'', count(*) from ?' >>>> select top 5 * from #rowcount >>>> order by tablename >>>> drop table #rowcount >>> >>> _______________________________________________ >>> 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 >> _______________________________________________ >> 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 fuller.artful at gmail.com Wed Jan 14 00:13:06 2009 From: fuller.artful at gmail.com (Arthur Fuller) Date: Wed, 14 Jan 2009 01:13:06 -0500 Subject: [dba-SQLServer] ?s on sp_MSForEachTable In-Reply-To: <099901c975a0$ec382750$2f8601c7@SusanOne> References: <099901c975a0$ec382750$2f8601c7@SusanOne> Message-ID: <29f585dd0901132213q766da243qa49f9e156c479116@mail.gmail.com> I am, and so is Tim Chapman, who has written a couple of extensions to it, available from www.techrepubic.com Arthur On Tue, Jan 13, 2009 at 12:03 PM, Susan Harkins wrote: > I ran the following statement against a copy of AdventureWorks, expecting > to > see some constraint errors: > > EXEC sp_MSForEachTable 'DELETE FROM ?' > > Instead, the command was completely successfully -- by message, but of > course, no data was deleted, which is what the statement should do -- > delete > all the records from every table in the database. Of course, I didn't > expect > it to work because of the constraints, but I did expect to see some kind of > error message. > > It's an undocumented sp and despite my efforts to figure this out, I'm not > finding any help. I've found a lot of information on the different > arguments > and how it's supposed to run, but answers to the above question -- why not > error message -- can't find that sort of information. > > Is anyone familiar with this sp? > > Susan H. > From ssharkins at gmail.com Wed Jan 14 07:55:47 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Wed, 14 Jan 2009 08:55:47 -0500 Subject: [dba-SQLServer] ?s on sp_MSForEachTable References: <099901c975a0$ec382750$2f8601c7@SusanOne> <29f585dd0901132213q766da243qa49f9e156c479116@mail.gmail.com> Message-ID: <005f01c9764f$da2128f0$2f8601c7@SusanOne> Maybe you can help. When I run the following statement EXEC sys.sp_MSForEachTable 'DELETE FROM ?' I should get an error on tables with constraints to other tables. Interesting, when I run TRUNCATE TABLE, I see those errors. With DELETE FROM, I see a message that the statement's been completed successfully instead of seeing the expected error messages for related tables. Should I see an error message for these tables or does it just happily delete what it can and ignore the tables it can't? Susan H. >I am, and so is Tim Chapman, who has written a couple of extensions to it, > available from www.techrepubic.com > >> I ran the following statement against a copy of AdventureWorks, expecting >> to >> see some constraint errors: >> >> EXEC sp_MSForEachTable 'DELETE FROM ?' >> >> Instead, the command was completely successfully -- by message, but of >> course, no data was deleted, which is what the statement should do -- >> delete >> all the records from every table in the database. Of course, I didn't >> expect >> it to work because of the constraints, but I did expect to see some kind >> of >> error message. >> >> It's an undocumented sp and despite my efforts to figure this out, I'm >> not >> finding any help. I've found a lot of information on the different >> arguments >> and how it's supposed to run, but answers to the above question -- why >> not >> error message -- can't find that sort of information. >> >> Is anyone familiar with this sp? >> >> Susan H. >> > _______________________________________________ > 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 Wed Jan 14 09:32:59 2009 From: fuller.artful at gmail.com (Arthur Fuller) Date: Wed, 14 Jan 2009 10:32:59 -0500 Subject: [dba-SQLServer] ?s on sp_MSForEachTable In-Reply-To: <005f01c9764f$da2128f0$2f8601c7@SusanOne> References: <099901c975a0$ec382750$2f8601c7@SusanOne> <29f585dd0901132213q766da243qa49f9e156c479116@mail.gmail.com> <005f01c9764f$da2128f0$2f8601c7@SusanOne> Message-ID: <29f585dd0901140732r77b64fbdk6cf8c839bec5f614@mail.gmail.com> Frankly I have never tried that. But I will build a test db using the fab data generator tool from Red Gate and manufacture some related tables and then repeat your exercise and see what happens. IMO Tim's stuff is superior to the built-in procedure since he extends it beyond tables, to include objects of any type. I will get back to you on this later today. A. On Wed, Jan 14, 2009 at 8:55 AM, Susan Harkins wrote: > Maybe you can help. When I run the following statement > > EXEC sys.sp_MSForEachTable 'DELETE FROM ?' > > I should get an error on tables with constraints to other tables. > Interesting, when I run TRUNCATE TABLE, I see those errors. With DELETE > FROM, I see a message that the statement's been completed successfully > instead of seeing the expected error messages for related tables. Should I > see an error message for these tables or does it just happily delete what > it > can and ignore the tables it can't? > > Susan H. > > > From ab-mi at post3.tele.dk Wed Jan 14 09:53:23 2009 From: ab-mi at post3.tele.dk (Asger Blond) Date: Wed, 14 Jan 2009 16:53:23 +0100 Subject: [dba-SQLServer] ?s on sp_MSForEachTable In-Reply-To: <005f01c9764f$da2128f0$2f8601c7@SusanOne> Message-ID: <000101c97660$3b603ab0$2301a8c0@AB> I tried this on both AdventureWorks using SQL Server 2000 and AdventureWorks2008 using SQL Server 2005, and I *did* get error messages for failing deletes due to constraint violations, as expected. Don't know why the error messages are missing in your setup. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af Susan Harkins Sendt: 14. januar 2009 14:56 Til: Discussion concerning MS SQL Server Emne: Re: [dba-SQLServer] ?s on sp_MSForEachTable Maybe you can help. When I run the following statement EXEC sys.sp_MSForEachTable 'DELETE FROM ?' I should get an error on tables with constraints to other tables. Interesting, when I run TRUNCATE TABLE, I see those errors. With DELETE FROM, I see a message that the statement's been completed successfully instead of seeing the expected error messages for related tables. Should I see an error message for these tables or does it just happily delete what it can and ignore the tables it can't? Susan H. >I am, and so is Tim Chapman, who has written a couple of extensions to it, > available from www.techrepubic.com > >> I ran the following statement against a copy of AdventureWorks, expecting >> to >> see some constraint errors: >> >> EXEC sp_MSForEachTable 'DELETE FROM ?' >> >> Instead, the command was completely successfully -- by message, but of >> course, no data was deleted, which is what the statement should do -- >> delete >> all the records from every table in the database. Of course, I didn't >> expect >> it to work because of the constraints, but I did expect to see some kind >> of >> error message. >> >> It's an undocumented sp and despite my efforts to figure this out, I'm >> not >> finding any help. I've found a lot of information on the different >> arguments >> and how it's supposed to run, but answers to the above question -- why >> not >> error message -- can't find that sort of information. >> >> Is anyone familiar with this sp? >> >> Susan H. >> > _______________________________________________ > 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 ssharkins at gmail.com Wed Jan 14 09:57:52 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Wed, 14 Jan 2009 10:57:52 -0500 Subject: [dba-SQLServer] ?s on sp_MSForEachTable References: <000101c97660$3b603ab0$2301a8c0@AB> Message-ID: <023e01c97660$dc638f20$2f8601c7@SusanOne> Well, that's good to know -- no clue what's going on at my end. Thank you for testing it. Susan H. I tried this on both AdventureWorks using SQL Server 2000 and AdventureWorks2008 using SQL Server 2005, and I *did* get error messages for failing deletes due to constraint violations, as expected. Don't know why the error messages are missing in your setup. Maybe you can help. When I run the following statement EXEC sys.sp_MSForEachTable 'DELETE FROM ?' I should get an error on tables with constraints to other tables. Interesting, when I run TRUNCATE TABLE, I see those errors. With DELETE FROM, I see a message that the statement's been completed successfully instead of seeing the expected error messages for related tables. Should I see an error message for these tables or does it just happily delete what it can and ignore the tables it can't? Susan H. From ab-mi at post3.tele.dk Wed Jan 14 10:01:51 2009 From: ab-mi at post3.tele.dk (Asger Blond) Date: Wed, 14 Jan 2009 17:01:51 +0100 Subject: [dba-SQLServer] ?s on sp_MSForEachTable In-Reply-To: <000101c97660$3b603ab0$2301a8c0@AB> Message-ID: <000201c97661$6a1c88d0$2301a8c0@AB> Sorry, please correct first sentence to "I tried this on both AdventureWorks using SQL Server 2005 and AdventureWorks2008 using SQL Server 2008". Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af Asger Blond Sendt: 14. januar 2009 16:53 Til: 'Discussion concerning MS SQL Server' Emne: Re: [dba-SQLServer] ?s on sp_MSForEachTable I tried this on both AdventureWorks using SQL Server 2000 and AdventureWorks2008 using SQL Server 2005, and I *did* get error messages for failing deletes due to constraint violations, as expected. Don't know why the error messages are missing in your setup. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af Susan Harkins Sendt: 14. januar 2009 14:56 Til: Discussion concerning MS SQL Server Emne: Re: [dba-SQLServer] ?s on sp_MSForEachTable Maybe you can help. When I run the following statement EXEC sys.sp_MSForEachTable 'DELETE FROM ?' I should get an error on tables with constraints to other tables. Interesting, when I run TRUNCATE TABLE, I see those errors. With DELETE FROM, I see a message that the statement's been completed successfully instead of seeing the expected error messages for related tables. Should I see an error message for these tables or does it just happily delete what it can and ignore the tables it can't? Susan H. >I am, and so is Tim Chapman, who has written a couple of extensions to it, > available from www.techrepubic.com > >> I ran the following statement against a copy of AdventureWorks, expecting >> to >> see some constraint errors: >> >> EXEC sp_MSForEachTable 'DELETE FROM ?' >> >> Instead, the command was completely successfully -- by message, but of >> course, no data was deleted, which is what the statement should do -- >> delete >> all the records from every table in the database. Of course, I didn't >> expect >> it to work because of the constraints, but I did expect to see some kind >> of >> error message. >> >> It's an undocumented sp and despite my efforts to figure this out, I'm >> not >> finding any help. I've found a lot of information on the different >> arguments >> and how it's supposed to run, but answers to the above question -- why >> not >> error message -- can't find that sort of information. >> >> Is anyone familiar with this sp? >> >> Susan H. >> > _______________________________________________ > 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 fhtapia at gmail.com Wed Jan 14 15:54:36 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Wed, 14 Jan 2009 13:54:36 -0800 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) In-Reply-To: <0bf401c975c5$36f8ec60$2f8601c7@SusanOne> References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> <0b6c01c975bf$31fa7270$2f8601c7@SusanOne> <0bac01c975c2$61682450$2f8601c7@SusanOne> <0be401c975c3$ab374b50$2f8601c7@SusanOne> <0bf401c975c5$36f8ec60$2f8601c7@SusanOne> Message-ID: Susan, Did you ever get this resolved? -Francisco http://sqlthis.blogspot.com | Tsql and More... On Tue, Jan 13, 2009 at 1:23 PM, Susan Harkins wrote: > Don't worry about it Martin -- it's my problem -- I'm sure I'm just > expecting the wrong thing. > > Susan H. > > > > Susan > > > > Sorry I am in the middle of AR on the new book. If you need this working > I > > can check it in the morning in work on another server with Adventure > works > > installed. Can spend a while on it then. > > > > Martin > > > > > > Martin WP Reid > > Information Services > > Queen's University > > Riddel Hall > > 185 Stranmillis Road > > Belfast > > BT9 5EE > > Tel : 02890974465 > > Email : mwp.reid at qub.ac.uk > > ________________________________________ > > From: dba-sqlserver-bounces at databaseadvisors.com > > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > > [ssharkins at gmail.com] > > Sent: 13 January 2009 21:12 > > To: Discussion concerning MS SQL Server > > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > > procedure) > > > > Most examples work -- the DELETE FROM ? that I've been trying doesn't > > return > > a result of course, just the Message tab that it's been completed > > successfully. > > > > Susan H. > > > > > >> Are you clicking the results tab? > >> > >> Martin > >> > >> > >> Martin WP Reid > >> Information Services > >> Queen's University > >> Riddel Hall > >> 185 Stranmillis Road > >> Belfast > >> BT9 5EE > >> Tel : 02890974465 > >> Email : mwp.reid at qub.ac.uk > >> ________________________________________ > >> From: dba-sqlserver-bounces at databaseadvisors.com > >> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins > >> [ssharkins at gmail.com] > >> Sent: 13 January 2009 21:03 > >> To: Discussion concerning MS SQL Server > >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > >> procedure) > >> > >> Okay, a little more experimenting and here's what's interesting. > >> > >> Mystery #1: When running against AdventureWorks, I have to use > >> master..sp_ > >> syntax, but others recognize sys.sp_ syntax. > >> Mystery #2: Even when using master..sp_ against AdventureWorks, it > >> recognizes the sp, but doesn't actually run it -- I get a message that > >> it's > >> been successfully completed, but it hasn't actually done a thing. > >> > >> Susan H. > >> > >> > >> > >> ----- Original Message ----- > >> From: "Martin Reid" > >> To: "Discussion concerning MS SQL Server" > >> > >> Sent: Tuesday, January 13, 2009 3:50 PM > >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored > >> procedure) > >> > >> > >>> Susan > >>> > >>> I ran it just there and it worked fine here I changed the database to a > >>> copy I have here and it worked fine. > >>> > >>> [dbo].[Customers] 29 > >>> [dbo].[Employee Privileges] 1 > >>> [dbo].[Employees] 9 > >>> [dbo].[Inventory Transaction Types] 4 > >>> [dbo].[Inventory Transactions] 102 > >>> > >>> use NWind > >>> go > >>> create table #rowcount (tablename varchar(128), rowcnt int) > >>> exec sp_MSforeachtable > >>> 'insert into #rowcount select ''?'', count(*) from ?' > >>> select top 5 * from #rowcount > >>> order by tablename > >>> drop table #rowcount > >>> > >>> > >>> Martin > >>> > >>> > >>> Martin WP Reid > >>> Information Services > >>> Queen's University > >>> Riddel Hall > >>> 185 Stranmillis Road > >>> Belfast > >>> BT9 5EE > >>> Tel : 02890974465 > >>> Email : mwp.reid at qub.ac.uk > >>> ________________________________________ > >>> From: dba-sqlserver-bounces at databaseadvisors.com > >>> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan > Harkins > >>> [ssharkins at gmail.com] > >>> Sent: 13 January 2009 20:38 > >>> To: Discussion concerning MS SQL Server > >>> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored > >>> procedure) > >>> > >>> I've tried several examples now -- they run, but they don't actually > >>> return > >>> anything -- this one creates the table, but doesn't fill it. > >>> > >>> Susan H. > >>> > >>> > >>>> Try this > >>>> > >>>> Just lifted it of the web > >>>> > >>>> use pubs > >>>> go > >>>> create table #rowcount (tablename varchar(128), rowcnt int) > >>>> exec sp_MSforeachtable > >>>> 'insert into #rowcount select ''?'', count(*) from ?' > >>>> select top 5 * from #rowcount > >>>> order by tablename > >>>> drop table #rowcount > >>> > >>> _______________________________________________ > >>> 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 > >> _______________________________________________ > >> 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 > > > > _______________________________________________ > 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 Wed Jan 14 17:17:46 2009 From: ssharkins at gmail.com (Susan Harkins) Date: Wed, 14 Jan 2009 18:17:46 -0500 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne><0b6c01c975bf$31fa7270$2f8601c7@SusanOne><0bac01c975c2$61682450$2f8601c7@SusanOne><0be401c975c3$ab374b50$2f8601c7@SusanOne><0bf401c975c5$36f8ec60$2f8601c7@SusanOne> Message-ID: <004501c9769e$832721e0$2f8601c7@SusanOne> Not really, but I didn't work on it today at all. I'll try again tomorrow and see what happens. Susan H. > Susan, > Did you ever get this resolved? > > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > > > On Tue, Jan 13, 2009 at 1:23 PM, Susan Harkins > wrote: > >> Don't worry about it Martin -- it's my problem -- I'm sure I'm just >> expecting the wrong thing. >> >> Susan H. >> >> >> > Susan >> > >> > Sorry I am in the middle of AR on the new book. If you need this >> > working >> I >> > can check it in the morning in work on another server with Adventure >> works >> > installed. Can spend a while on it then. >> > >> > Martin >> > >> > >> > Martin WP Reid >> > Information Services >> > Queen's University >> > Riddel Hall >> > 185 Stranmillis Road >> > Belfast >> > BT9 5EE >> > Tel : 02890974465 >> > Email : mwp.reid at qub.ac.uk >> > ________________________________________ >> > From: dba-sqlserver-bounces at databaseadvisors.com >> > [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan Harkins >> > [ssharkins at gmail.com] >> > Sent: 13 January 2009 21:12 >> > To: Discussion concerning MS SQL Server >> > Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored >> > procedure) >> > >> > Most examples work -- the DELETE FROM ? that I've been trying doesn't >> > return >> > a result of course, just the Message tab that it's been completed >> > successfully. >> > >> > Susan H. >> > >> > >> >> Are you clicking the results tab? >> >> >> >> Martin >> >> >> >> >> >> Martin WP Reid >> >> Information Services >> >> Queen's University >> >> Riddel Hall >> >> 185 Stranmillis Road >> >> Belfast >> >> BT9 5EE >> >> Tel : 02890974465 >> >> Email : mwp.reid at qub.ac.uk >> >> ________________________________________ >> >> From: dba-sqlserver-bounces at databaseadvisors.com >> >> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan >> >> Harkins >> >> [ssharkins at gmail.com] >> >> Sent: 13 January 2009 21:03 >> >> To: Discussion concerning MS SQL Server >> >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored >> >> procedure) >> >> >> >> Okay, a little more experimenting and here's what's interesting. >> >> >> >> Mystery #1: When running against AdventureWorks, I have to use >> >> master..sp_ >> >> syntax, but others recognize sys.sp_ syntax. >> >> Mystery #2: Even when using master..sp_ against AdventureWorks, it >> >> recognizes the sp, but doesn't actually run it -- I get a message that >> >> it's >> >> been successfully completed, but it hasn't actually done a thing. >> >> >> >> Susan H. >> >> >> >> >> >> >> >> ----- Original Message ----- >> >> From: "Martin Reid" >> >> To: "Discussion concerning MS SQL Server" >> >> >> >> Sent: Tuesday, January 13, 2009 3:50 PM >> >> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing systemstored >> >> procedure) >> >> >> >> >> >>> Susan >> >>> >> >>> I ran it just there and it worked fine here I changed the database to >> >>> a >> >>> copy I have here and it worked fine. >> >>> >> >>> [dbo].[Customers] 29 >> >>> [dbo].[Employee Privileges] 1 >> >>> [dbo].[Employees] 9 >> >>> [dbo].[Inventory Transaction Types] 4 >> >>> [dbo].[Inventory Transactions] 102 >> >>> >> >>> use NWind >> >>> go >> >>> create table #rowcount (tablename varchar(128), rowcnt int) >> >>> exec sp_MSforeachtable >> >>> 'insert into #rowcount select ''?'', count(*) from ?' >> >>> select top 5 * from #rowcount >> >>> order by tablename >> >>> drop table #rowcount >> >>> >> >>> >> >>> Martin >> >>> >> >>> >> >>> Martin WP Reid >> >>> Information Services >> >>> Queen's University >> >>> Riddel Hall >> >>> 185 Stranmillis Road >> >>> Belfast >> >>> BT9 5EE >> >>> Tel : 02890974465 >> >>> Email : mwp.reid at qub.ac.uk >> >>> ________________________________________ >> >>> From: dba-sqlserver-bounces at databaseadvisors.com >> >>> [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan >> Harkins >> >>> [ssharkins at gmail.com] >> >>> Sent: 13 January 2009 20:38 >> >>> To: Discussion concerning MS SQL Server >> >>> Subject: Re: [dba-SQLServer] NEVERMIND (Fw: executing system stored >> >>> procedure) >> >>> >> >>> I've tried several examples now -- they run, but they don't actually >> >>> return >> >>> anything -- this one creates the table, but doesn't fill it. >> >>> >> >>> Susan H. >> >>> >> >>> >> >>>> Try this >> >>>> >> >>>> Just lifted it of the web >> >>>> >> >>>> use pubs >> >>>> go >> >>>> create table #rowcount (tablename varchar(128), rowcnt int) >> >>>> exec sp_MSforeachtable >> >>>> 'insert into #rowcount select ''?'', count(*) from ?' >> >>>> select top 5 * from #rowcount >> >>>> order by tablename >> >>>> drop table #rowcount >> >>> >> >>> _______________________________________________ >> >>> 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 >> >> _______________________________________________ >> >> 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 >> > >> >> _______________________________________________ >> 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 fhtapia at gmail.com Thu Jan 15 10:18:57 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 15 Jan 2009 08:18:57 -0800 Subject: [dba-SQLServer] NEVERMIND (Fw: executing systemstored procedure) In-Reply-To: <004501c9769e$832721e0$2f8601c7@SusanOne> References: <0b0701c975bc$6b14b370$2f8601c7@SusanOne> <0b6c01c975bf$31fa7270$2f8601c7@SusanOne> <0bac01c975c2$61682450$2f8601c7@SusanOne> <0be401c975c3$ab374b50$2f8601c7@SusanOne> <0bf401c975c5$36f8ec60$2f8601c7@SusanOne> <004501c9769e$832721e0$2f8601c7@SusanOne> Message-ID: the general syntax that I use is: --Lifted from the web... CREATE TABLE #tblTableData ( vchTableName VARCHAR(100) NOT NULL, intRows INT NOT NULL, vchReservedSpace VARCHAR(100) NOT NULL, vchData VARCHAR(100) NOT NULL, vchIndexSize VARCHAR(100) NOT NULL, vchUnusedSpace VARCHAR(100) NOT NULL ; ) INSERT INTO #tblTableData EXEC sp_MSforeachtable 'sp_spaceused ''?''' SELECT * FROM #tblTableData DROP TABLE #tblTableData -Francisco http://sqlthis.blogspot.com | Tsql and More... On Wed, Jan 14, 2009 at 3:17 PM, Susan Harkins wrote: > Not really, but I didn't work on it today at all. I'll try again tomorrow > and see what happens. > > Susan H. > > > > Susan, > > Did you ever get this resolved? > > > > -Francisco > > http://sqlthis.blogspot.com | Tsql and More... > > > > > > On Tue, Jan 13, 2009 at 1:23 PM, Susan Harkins > > wrote: > > > >> Don't worry about it Martin -- it's my problem -- I'm sure I'm just > >> expecting the wrong thing. > >> > >> Susan H. > >> > >> > >> > Susan > >> > > >> > Sorry I am in the middle of AR on the new book. If you need this > >> > working > >> I > >> > can check it in the morning in work on another server with Adventure > >> works > >> > installed. Can spend a while on it then. > >> > > >> > Martin > >> > > >> > > >> > Martin WP Reid > >> > Information Services > >> > Queen's University > >> > Riddel Hall > >> > 185 Stranmillis Road > >> > Belfast > >> > BT9 5EE > >> > Tel : 02890974465 > >> > Email : mwp.reid at qub.ac.uk > >> > __________________________ > From fhtapia at gmail.com Thu Jan 29 16:00:36 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 29 Jan 2009 14:00:36 -0800 Subject: [dba-SQLServer] [AccessD] Stored Procedure return value In-Reply-To: <49822469.8050103@colbyconsulting.com> References: <000701c98197$c86ef710$2301a8c0@AB> <4981C3FF.8010306@colbyconsulting.com> <49822469.8050103@colbyconsulting.com> Message-ID: It is possible, and it's quite robust, I have sql server 2005 standard and it is running for me. You will want to read up on Microsoft's website on how to setup debugging for sql server 2005. there is a simple step to go through and that's that. if you read through MS' site it's quite difficult to figure it out, but if you check google there are tons of site having this information. -Francisco http://sqlthis.blogspot.com | Tsql and More... On Thu, Jan 29, 2009 at 1:49 PM, jwcolby wrote: > I see nothing there about debugging stored procedures. I > Googled and found that IF you happen to own the advanced > versions of VS you could use them to do debugging. > Unfortunately I only own the standard edition. > > According to what I read, the debugging was migrated out to > VS in 2005, and the standard edition of VS would NOT do it. > > John W. Colby > www.ColbyConsulting.com > > > Francisco Tapia wrote: > > Debugging of stored procedures is available in Sql Server 2000 and Sql > > Server 2005, in fact it's quite robust. > > -Francisco > > http://sqlthis.blogspot.com | Tsql and More... > > > > > > On Thu, Jan 29, 2009 at 6:58 AM, jwcolby > wrote > > > > > >> > >> > >> My problem in all of this is that I very much a novice at > >> SQL Server. I have been forced to dig in but, like Access, > >> there is just so much to know. If I sit here just > >> "experimenting" trying this and that I get nowhere. There > >> is no "debugger" for SPs so it is "try something, run and > >> see". Worse yet the totality of the feedback is "error near > >> XXX in line YYY", not exactly stellar help. > >> > > > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > From fhtapia at gmail.com Thu Jan 29 16:01:02 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 29 Jan 2009 14:01:02 -0800 Subject: [dba-SQLServer] [AccessD] Stored Procedure return value In-Reply-To: <49822469.8050103@colbyconsulting.com> References: <000701c98197$c86ef710$2301a8c0@AB> <4981C3FF.8010306@colbyconsulting.com> <49822469.8050103@colbyconsulting.com> Message-ID: It is possible, and it's quite robust, I have sql server 2005 standard and it is running for me. You will want to read up on Microsoft's website on how to setup debugging for sql server 2005. there is a simple step to go through and that's that. if you read through MS' site it's quite difficult to figure it out, but if you check google there are tons of site having this information. -Francisco http://sqlthis.blogspot.com | Tsql and More... On Thu, Jan 29, 2009 at 1:49 PM, jwcolby wrote: > I see nothing there about debugging stored procedures. I > Googled and found that IF you happen to own the advanced > versions of VS you could use them to do debugging. > Unfortunately I only own the standard edition. > > According to what I read, the debugging was migrated out to > VS in 2005, and the standard edition of VS would NOT do it. > > John W. Colby > www.ColbyConsulting.com > > > Francisco Tapia wrote: > > Debugging of stored procedures is available in Sql Server 2000 and Sql > > Server 2005, in fact it's quite robust. > > -Francisco > > http://sqlthis.blogspot.com | Tsql and More... > > > > > > On Thu, Jan 29, 2009 at 6:58 AM, jwcolby > wrote > > > > > >> > >> > >> My problem in all of this is that I very much a novice at > >> SQL Server. I have been forced to dig in but, like Access, > >> there is just so much to know. If I sit here just > >> "experimenting" trying this and that I get nowhere. There > >> is no "debugger" for SPs so it is "try something, run and > >> see". Worse yet the totality of the feedback is "error near > >> XXX in line YYY", not exactly stellar help. > >> > > > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > From Robert at webedb.com Fri Jan 30 13:37:03 2009 From: Robert at webedb.com (Robert) Date: Fri, 30 Jan 2009 14:37:03 -0500 Subject: [dba-SQLServer] SPAM-MED: dba-SQLServer Digest, Vol 71, Issue 6 Message-ID: <39a5610e1a0148b8a7a668e729e0d0d6@webedb.com> John, If you are dealing with learning the syntax and issues with it, I would suggest getting SQL Refactor from Red Gate. It will give you an underline at the offending place. It was and continues to be a tool that I use all the time. They have another tool that adds intelli-sense into the management studio that also might be helpful to you. Personally, I have never been able to get debugging working correctly on 2005. Robert ---------------------------------------- > >> My problem in all of this is that I very much a novice at > >> SQL Server. I have been forced to dig in but, like Access, > >> there is just so much to know. If I sit here just > >> "experimenting" trying this and that I get nowhere. There > >> is no "debugger" for SPs so it is "try something, run and > >> see". Worse yet the totality of the feedback is "error near > >> XXX in line YYY", not exactly stellar help. From fhtapia at gmail.com Fri Jan 30 15:10:22 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Fri, 30 Jan 2009 13:10:22 -0800 Subject: [dba-SQLServer] SPAM-MED: dba-SQLServer Digest, Vol 71, Issue 6 In-Reply-To: <39a5610e1a0148b8a7a668e729e0d0d6@webedb.com> References: <39a5610e1a0148b8a7a668e729e0d0d6@webedb.com> Message-ID: Robert, I found out later that John does not subscribe to the sql list, that's too bad. But this is an interesting topic as I did verify my version of Visual Studio 2005 and it is PRO thus why I have the debug option for the stored procedures (something nobody tells you until you are derailed while trying to debug.) In Visual Studio 2008 I have the standard edition and found myself in the same boat as Colby which is no debugger :(, quite frustrating because I received this copy from MS for their 2008 launch event, why would they give you Sql Server 2008 w/o a debugging utility? I mean really if you are a DBA you'd want that tool, so instead of just a Sql License they are pinching you for two licenses! STILL... M$ does continue to have the best IDE out there so I guess I should not complain too loudly. BTW, I have used Refractor which is a very cool tool. and I do use Sql Prompt, which is way nice. Refractor turned out to be an excellent tool for my other DBA here, whom never seems to organize his sprocs / views into readable formats... thus Refractor has been a very very good tool to help his coding style. Do others here use similar Sql Tools? -Francisco http://sqlthis.blogspot.com | Tsql and More... On Fri, Jan 30, 2009 at 11:37 AM, Robert wrote: > > John, > > If you are dealing with learning the syntax and issues with it, I would > suggest getting SQL Refactor from Red Gate. It will give you an underline at > the offending place. It was and continues to be a tool that I use all the > time. They have another tool that adds intelli-sense into the management > studio that also might be helpful to you. > > Personally, I have never been able to get debugging working correctly on > 2005. > > Robert > > ---------------------------------------- > > > >> My problem in all of this is that I very much a novice > at > > >> SQL Server. I have been forced to dig in but, like Access, > > >> there is just so much to know. If I sit here just > > >> "experimenting" trying this and that I get nowhere. There > > >> is no "debugger" for SPs so it is "try something, run and > > >> see". Worse yet the totality of the feedback is "error near > > >> XXX in line YYY", not exactly stellar help. > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Fri Jan 30 22:58:45 2009 From: jnatola at hotmail.com (jean-paul) Date: Fri, 30 Jan 2009 23:58:45 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement Message-ID: Hi all, So I was attempting to for the first time to get data using the select statment here was my first syntax SELECT * FROM `contacts` WHERE 1 it returned all the records (as I wanted) 9050 records contact name address emaill etcc.. now there is another table called contacts_organization_types I wanted the corresponding output to come out in the same query so i tried this SELECT * FROM `contacts`,`contacts_organization_types` WHERE 1 now i got the same results as above- but instead of it adding the field to the list it returned each record from the contacts with every single cust_org_types for example first statement results; id first name last name email 1 jp natola second statment results; id first name last name email organaization type 1 jp natola NGO 1 jp natola MED 1 jp natola Donor 1 jp natola Education 1 jp natola Media How do i modify the statement to just give me the record with the actual value that is in the contacts record thanks _________________________________________________________________ Hotmail? goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 From fhtapia at gmail.com Fri Jan 30 23:25:49 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Fri, 30 Jan 2009 21:25:49 -0800 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: Jean Paul, You'll want to define your where criteria... that is: SELECT * FROM contacts AS ctc WHERE NAME = 'Criteria' this way the results are what you expect To join two tables you will want to associate the corresponding fields Such as: SELECT * FROM contacts AS ctcs INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id WHERE ctcs.name = 'Criteria' some interesting things are happening here... first I have used a table alias that's where you see the table name contacts followed by the keyword AS then an abbreviation of my liking (no reserved words) such as ctcs so I 'm telling the engine that I will from that point on substitute the use of ctcs whenever it expects to see an explicit reference for the table name contacts. Also if you take a look at the criteria, you'll notice that I have a field name in there the name I took from your example but it should be any valid name in your table that you want to search against... saying WHERE 1 is a true statement, but does not reflect the case of WHERE id = 1, so you may want to revise your select statement. -Francisco http://sqlthis.blogspot.com | Tsql and More... On Fri, Jan 30, 2009 at 8:58 PM, jean-paul wrote: > > Hi all, > > So I was attempting to for the first time to get data using the select > statment > > here was my first syntax > SELECT * FROM `contacts` WHERE 1 > > it returned all the records (as I wanted) 9050 records > contact name address emaill etcc.. > now there is another table called contacts_organization_types > I wanted the corresponding output to come out in the same query > > so i tried this > SELECT * FROM `contacts`,`contacts_organization_types` WHERE 1 > > now i got the same results as above- but instead of it adding the field > to the list it returned each record from the contacts with every single > cust_org_types for example > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > first statement results; > > id first name last name email > 1 jp natola > > > second statment results; > > > > id first name last name email organaization type > 1 jp natola NGO > > > 1 jp natola MED > > 1 jp natola Donor > > 1 jp natola Education > > 1 jp natola Media > > How do i modify the statement to just give me the record with the actual > value that is in the contacts record > > thanks > > > > > > > > > > _________________________________________________________________ > Hotmail(R) goes where you go. On a PC, on the Web, on your phone. > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Fri Jan 30 23:39:34 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 00:39:34 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: you flew way over my head on that one- in the db all contacts have a value in the org type field from the second table I want ALL the contacts from the contacts table and Im NOT looking for a specific criteria from the contacts_org_tpes I just want it to return the value Jean-Paul Natola > Date: Fri, 30 Jan 2009 21:25:49 -0800 > From: fhtapia at gmail.com > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] Newbie needs help with select statement > > Jean Paul, > You'll want to define your where criteria... that is: > > SELECT * FROM contacts AS ctc WHERE NAME = 'Criteria' > > this way the results are what you expect > > To join two tables you will want to associate the corresponding fields > > Such as: > > SELECT * FROM contacts AS ctcs > INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id > WHERE ctcs.name = 'Criteria' > > some interesting things are happening here... first I have used a table > alias that's where you see the table name contacts followed by the keyword > AS then an abbreviation of my liking (no reserved words) such as ctcs > > so I 'm telling the engine that I will from that point on substitute the use > of ctcs whenever it expects to see an explicit reference for the table name > contacts. Also if you take a look at the criteria, you'll notice that I > have a field name in there the name I took from your example but it should > be any valid name in your table that you want to search against... saying > WHERE 1 is a true statement, but does not reflect the case of WHERE id = 1, > so you may want to revise your select statement. > > > > -Francisco > http://sqlthis.blogspot.com | Tsql and More... > > > On Fri, Jan 30, 2009 at 8:58 PM, jean-paul wrote: > > > > > Hi all, > > > > So I was attempting to for the first time to get data using the select > > statment > > > > here was my first syntax > > SELECT * FROM `contacts` WHERE 1 > > > > it returned all the records (as I wanted) 9050 records > > contact name address emaill etcc.. > > now there is another table called contacts_organization_types > > I wanted the corresponding output to come out in the same query > > > > so i tried this > > SELECT * FROM `contacts`,`contacts_organization_types` WHERE 1 > > > > now i got the same results as above- but instead of it adding the field > > to the list it returned each record from the contacts with every single > > cust_org_types for example > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > first statement results; > > > > id first name last name email > > 1 jp natola > > > > > > second statment results; > > > > > > > > id first name last name email organaization type > > 1 jp natola NGO > > > > > > 1 jp natola MED > > > > 1 jp natola Donor > > > > 1 jp natola Education > > > > 1 jp natola Media > > > > How do i modify the statement to just give me the record with the actual > > value that is in the contacts record > > > > thanks > > > > > > > > > > > > > > > > > > > > _________________________________________________________________ > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone. > > > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 > > _______________________________________________ > > 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 > _________________________________________________________________ Windows Live? Hotmail??more than just e-mail. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009 From fhtapia at gmail.com Fri Jan 30 23:43:12 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Fri, 30 Jan 2009 21:43:12 -0800 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: In that case simply omit the Where clause no need to have it if you are not using it. SELECT * FROM contacts AS ctcs INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id -Francisco http://sqlthis.blogspot.com | Tsql and More... On Fri, Jan 30, 2009 at 9:39 PM, jean-paul wrote: > > you flew way over my head on that one- > > in the db all contacts have a value in the org type field from the second > table > > > I want ALL the contacts from the contacts table > and Im NOT looking for a specific criteria from the contacts_org_tpes I > just want it to return the value > > > > > > > > > > > > > > > > > > > > > > Jean-Paul Natola > > > > > > > > Date: Fri, 30 Jan 2009 21:25:49 -0800 > > From: fhtapia at gmail.com > > To: dba-sqlserver at databaseadvisors.com > > Subject: Re: [dba-SQLServer] Newbie needs help with select statement > > > > Jean Paul, > > You'll want to define your where criteria... that is: > > > > SELECT * FROM contacts AS ctc WHERE NAME = 'Criteria' > > > > this way the results are what you expect > > > > To join two tables you will want to associate the corresponding fields > > > > Such as: > > > > SELECT * FROM contacts AS ctcs > > INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id > > WHERE ctcs.name = 'Criteria' > > > > some interesting things are happening here... first I have used a table > > alias that's where you see the table name contacts followed by the > keyword > > AS then an abbreviation of my liking (no reserved words) such as ctcs > > > > so I 'm telling the engine that I will from that point on substitute the > use > > of ctcs whenever it expects to see an explicit reference for the table > name > > contacts. Also if you take a look at the criteria, you'll notice that I > > have a field name in there the name I took from your example but it > should > > be any valid name in your table that you want to search against... saying > > WHERE 1 is a true statement, but does not reflect the case of WHERE id = > 1, > > so you may want to revise your select statement. > > > > > > > > -Francisco > > http://sqlthis.blogspot.com | Tsql and More... > > > > > > On Fri, Jan 30, 2009 at 8:58 PM, jean-paul wrote: > > > > > > > > Hi all, > > > > > > So I was attempting to for the first time to get data using the select > > > statment > > > > > > here was my first syntax > > > SELECT * FROM `contacts` WHERE 1 > > > > > > it returned all the records (as I wanted) 9050 records > > > contact name address emaill etcc.. > > > now there is another table called contacts_organization_types > > > I wanted the corresponding output to come out in the same query > > > > > > so i tried this > > > SELECT * FROM `contacts`,`contacts_organization_types` WHERE 1 > > > > > > now i got the same results as above- but instead of it adding the > field > > > to the list it returned each record from the contacts with every single > > > cust_org_types for example > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > first statement results; > > > > > > id first name last name email > > > 1 jp natola > > > > > > > > > second statment results; > > > > > > > > > > > > id first name last name email organaization type > > > 1 jp natola NGO > > > > > > > > > 1 jp natola MED > > > > > > 1 jp natola Donor > > > > > > 1 jp natola Education > > > > > > 1 jp natola Media > > > > > > How do i modify the statement to just give me the record with the > actual > > > value that is in the contacts record > > > > > > thanks > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _________________________________________________________________ > > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone. > > > > > > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 > > > _______________________________________________ > > > 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 > > > > _________________________________________________________________ > Windows Live? Hotmail(R)?more than just e-mail. > > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Fri Jan 30 23:47:57 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 00:47:57 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: that yielded MySQL returned an empty result set (i.e. zero rows). (Query took 0.0007 sec) Jean-Paul Natola > Date: Fri, 30 Jan 2009 21:43:12 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > In that case simply omit the Where clause no need to have it if you are not> using it.> > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id> > -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Fri, Jan 30, 2009 at 9:39 PM, jean-paul wrote:> > >> > you flew way over my head on that one-> >> > in the db all contacts have a value in the org type field from the second> > table> >> >> > I want ALL the contacts from the contacts table> > and Im NOT looking for a specific criteria from the contacts_org_tpes I> > just want it to return the value> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> > Jean-Paul Natola> >> >> >> >> >> >> > > Date: Fri, 30 Jan 2009 21:25:49 -0800> > > From: fhtapia at gmail.com> > > To: dba-sqlserver at databaseadvisors.com> > > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > >> > > Jean Paul,> > > You'll want to define your where criteria... that is:> > >> > > SELECT * FROM contacts AS ctc WHERE NAME = 'Criteria'> > >> > > this way the results are what you expect> > >> > > To join two tables you will want to associate the corresponding fields> > >> > > Such as:> > >> > > SELECT * FROM contacts AS ctcs> > > INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id> > > WHERE ctcs.name = 'Criteria'> > >> > > some interesting things are happening here... first I have used a table> > > alias that's where you see the table name contacts followed by the> > keyword> > > AS then an abbreviation of my liking (no reserved words) such as ctcs> > >> > > so I 'm telling the engine that I will from that point on substitute the> > use> > > of ctcs whenever it expects to see an explicit reference for the table> > name> > > contacts. Also if you take a look at the criteria, you'll notice that I> > > have a field name in there the name I took from your example but it> > should> > > be any valid name in your table that you want to search against... saying> > > WHERE 1 is a true statement, but does not reflect the case of WHERE id => > 1,> > > so you may want to revise your select statement.> > >> > >> > >> > > -Francisco> > > http://sqlthis.blogspot.com | Tsql and More...> > >> > >> > > On Fri, Jan 30, 2009 at 8:58 PM, jean-paul wrote:> > >> > > >> > > > Hi all,> > > >> > > > So I was attempting to for the first time to get data using the select> > > > statment> > > >> > > > here was my first syntax> > > > SELECT * FROM `contacts` WHERE 1> > > >> > > > it returned all the records (as I wanted) 9050 records> > > > contact name address emaill etcc..> > > > now there is another table called contacts_organization_types> > > > I wanted the corresponding output to come out in the same query> > > >> > > > so i tried this> > > > SELECT * FROM `contacts`,`contacts_organization_types` WHERE 1> > > >> > > > now i got the same results as above- but instead of it adding the> > field> > > > to the list it returned each record from the contacts with every single> > > > cust_org_types for example> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > first statement results;> > > >> > > > id first name last name email> > > > 1 jp natola> > > >> > > >> > > > second statment results;> > > >> > > >> > > >> > > > id first name last name email organaization type> > > > 1 jp natola NGO> > > >> > > >> > > > 1 jp natola MED> > > >> > > > 1 jp natola Donor> > > >> > > > 1 jp natola Education> > > >> > > > 1 jp natola Media> > > >> > > > How do i modify the statement to just give me the record with the> > actual> > > > value that is in the contacts record> > > >> > > > thanks> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > _________________________________________________________________> > > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> > > >> > > >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > > > _______________________________________________> > > > 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> > >> >> > _________________________________________________________________> > Windows Live? Hotmail(R)?more than just e-mail.> >> > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009> > _______________________________________________> > 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> _________________________________________________________________ Hotmail? goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 From markamatte at hotmail.com Sat Jan 31 06:49:06 2009 From: markamatte at hotmail.com (Mark A Matte) Date: Sat, 31 Jan 2009 12:49:06 +0000 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: I hate to make assumptions...but the subject says 'newbie'...and Francisco suggested the fields to join on...not Jean Paul. Jean Paul, what fields from each table are you trying to join on(the actual field names)? If the example below was used 'as is' and there is an 'ID' field in each table but its not the relationship between these two tables...won't give the results. As long as I am 'assuming'...I think the scenario might be a translation table...and the first attemp produced a cartesian join(no joins) and listed each contact having every kind of cust_org_types...so the confusion might be what fields to join on. Francisco's Example modified: > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.cust_org_types = cot.id I'm guessing there is a cust_org_types field in the contacts table...and there is a value that needs to be translated? If I am off target...please let me know. Thanks, Mark A. Matte> Date: Fri, 30 Jan 2009 21:43:12 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > In that case simply omit the Where clause no need to have it if you are not> using it.> > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id> > -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Fri, Jan 30, 2009 at 9:39 PM, jean-paul wrote:> > >> > you flew way over my head on that one-> >> > in the db all contacts have a value in the org type field from the second> > table> >> >> > I want ALL the contacts from the contacts table> > and Im NOT looking for a specific criteria from the contacts_org_tpes I> > just want it to return the value> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> > Jean-Paul Natola> >> >> >> >> >> >> > > Date: Fri, 30 Jan 2009 21:25:49 -0800> > > From: fhtapia at gmail.com> > > To: dba-sqlserver at databaseadvisors.com> > > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > >> > > Jean Paul,> > > You'll want to define your where criteria... that is:> > >> > > SELECT * FROM contacts AS ctc WHERE NAME = 'Criteria'> > >> > > this way the results are what you expect> > >> > > To join two tables you will want to associate the corresponding fields> > >> > > Such as:> > >> > > SELECT * FROM contacts AS ctcs> > > INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id> > > WHERE ctcs.name = 'Criteria'> > >> > > some interesting things are happening here... first I have used a table> > > alias that's where you see the table name contacts followed by the> > keyword> > > AS then an abbreviation of my liking (no reserved words) such as ctcs> > >> > > so I 'm telling the engine that I will from that point on substitute the> > use> > > of ctcs whenever it expects to see an explicit reference for the table> > name> > > contacts. Also if you take a look at the criteria, you'll notice that I> > > have a field name in there the name I took from your example but it> > should> > > be any valid name in your table that you want to search against... saying> > > WHERE 1 is a true statement, but does not reflect the case of WHERE id => > 1,> > > so you may want to revise your select statement.> > >> > >> > >> > > -Francisco> > > http://sqlthis.blogspot.com | Tsql and More...> > >> > >> > > On Fri, Jan 30, 2009 at 8:58 PM, jean-paul wrote:> > >> > > >> > > > Hi all,> > > >> > > > So I was attempting to for the first time to get data using the select> > > > statment> > > >> > > > here was my first syntax> > > > SELECT * FROM `contacts` WHERE 1> > > >> > > > it returned all the records (as I wanted) 9050 records> > > > contact name address emaill etcc..> > > > now there is another table called contacts_organization_types> > > > I wanted the corresponding output to come out in the same query> > > >> > > > so i tried this> > > > SELECT * FROM `contacts`,`contacts_organization_types` WHERE 1> > > >> > > > now i got the same results as above- but instead of it adding the> > field> > > > to the list it returned each record from the contacts with every single> > > > cust_org_types for example> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > first statement results;> > > >> > > > id first name last name email> > > > 1 jp natola> > > >> > > >> > > > second statment results;> > > >> > > >> > > >> > > > id first name last name email organaization type> > > > 1 jp natola NGO> > > >> > > >> > > > 1 jp natola MED> > > >> > > > 1 jp natola Donor> > > >> > > > 1 jp natola Education> > > >> > > > 1 jp natola Media> > > >> > > > How do i modify the statement to just give me the record with the> > actual> > > > value that is in the contacts record> > > >> > > > thanks> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > _________________________________________________________________> > > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> > > >> > > >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > > > _______________________________________________> > > > 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> > >> >> > _________________________________________________________________> > Windows Live? Hotmail(R)?more than just e-mail.> >> > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009> > _______________________________________________> > 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> _________________________________________________________________ Windows Live?: E-mail. Chat. Share. Get more ways to connect. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009 From fhtapia at gmail.com Sat Jan 31 10:48:34 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Sat, 31 Jan 2009 08:48:34 -0800 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: the join criteria I specified was: ON ctcs.ID = cot.id so ID should match ID based off his example maybe add brakets around this field ie, ctcs.[ID] = cot.[ID] -Francisco http://sqlthis.blogspot.com | Tsql and More... On Sat, Jan 31, 2009 at 4:49 AM, Mark A Matte wrote: > > I hate to make assumptions...but the subject says 'newbie'...and Francisco > suggested the fields to join on...not Jean Paul. > > Jean Paul, what fields from each table are you trying to join on(the actual > field names)? > > If the example below was used 'as is' and there is an 'ID' field in each > table but its not the relationship between these two tables...won't give the > results. > > As long as I am 'assuming'...I think the scenario might be a translation > table...and the first attemp produced a cartesian join(no joins) and listed > each contact having every kind of cust_org_types...so the confusion might be > what fields to join on. > > Francisco's Example modified: > > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS > cot ON ctcs.cust_org_types = cot.id > > I'm guessing there is a cust_org_types field in the contacts table...and > there is a value that needs to be translated? > > If I am off target...please let me know. > > Thanks, > > > Mark A. Matte> Date: Fri, 30 Jan 2009 21:43:12 -0800> From: > fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: > [dba-SQLServer] Newbie needs help with select statement> > In that case > simply omit the Where clause no need to have it if you are not> using it.> > > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS > cot ON ctcs.ID = cot.id> > -Francisco> http://sqlthis.blogspot.com | Tsql > and More...> > > On Fri, Jan 30, 2009 at 9:39 PM, jean-paul < > jnatola at hotmail.com> wrote:> > >> > you flew way over my head on that > one-> >> > in the db all contacts have a value in the org type field from > the second> > table> >> >> > I want ALL the contacts from the contacts > table> > and Im NOT looking for a specific criteria from the > contacts_org_tpes I> > just want it to return the value> >> >> >> >> >> >> > >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> > Jean-Paul Natola> >> >> >> >> > >> >> > > Date: Fri, 30 Jan 2009 21:25:49 -0800> > > From: > fhtapia at gmail.com> > > To: dba-sqlserver at databaseadvisors.com> > > > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > >> > > > Jean Paul,> > > You'll want to define your where criteria... that is:> > > >> > > SELECT * FROM contacts AS ctc WHERE NAME = 'Criteria'> > >> > > this > way the results are what you expect> > >> > > To join two tables you will > want to associate the corresponding fields> > >> > > Such as:> > >> > > > SELECT * FROM contacts AS ctcs> > > INNER JOIN contacts_organization_types > AS cot ON ctcs.ID = cot.id> > > WHERE ctcs.name = 'Criteria'> > >> > > > some interesting things are happening here... first I have used a table> > > > alias that's where you see the table name contacts followed by the> > > keyword> > > AS then an abbreviation of my liking (no reserved words) such > as ctcs> > >> > > so I 'm telling the engine that I will from that point on > substitute the> > use> > > of ctcs whenever it expects to see an explicit > reference for the table> > name> > > contacts. Also if you take a look at > the criteria, you'll notice that I> > > have a field name in there the name > I took from your example but it> > should> > > be any valid name in your > table that you want to search against... saying> > > WHERE 1 is a true > statement, but does not reflect the case of WHERE id => > 1,> > > so you may > want to revise your select statement.> > >> > >> > >> > > -Francisco> > > > http://sqlthis.blogspot.com | Tsql and More...> > >> > >> > > On Fri, Jan > 30, 2009 at 8:58 PM, jean-paul wrote:> > >> > > >> > > > > Hi all,> > > >> > > > So I was attempting to for the first time to get > data using the select> > > > statment> > > >> > > > here was my first > syntax> > > > SELECT * FROM `contacts` WHERE 1> > > >> > > > it returned all > the records (as I wanted) 9050 records> > > > contact name address emaill > etcc..> > > > now there is another table called contacts_organization_types> > > > > I wanted the corresponding output to come out in the same query> > > > >> > > > so i tried this> > > > SELECT * FROM > `contacts`,`contacts_organization_types` WHERE 1> > > >> > > > now i got the > same results as above- but instead of it adding the> > field> > > > to the > list it returned each record from the contacts with every single> > > > > cust_org_types for example> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > >> > > >> > > >> > > >> > > >> > > > first statement results;> > > >> > > > > id first name last name email> > > > 1 jp natola> > > >> > > >> > > > > second statment results;> > > >> > > >> > > >> > > > id first name last name > email organaization type> > > > 1 jp natola NGO> > > >> > > >> > > > 1 jp > natola MED> > > >> > > > 1 jp natola Donor> > > >> > > > 1 jp natola > Education> > > >> > > > 1 jp natola Media> > > >> > > > How do i modify the > statement to just give me the record with the> > actual> > > > value that is > in the contacts record> > > >> > > > thanks> > > >> > > >> > > >> > > >> > > > >> > > >> > > >> > > >> > > >> > > > > _________________________________________________________________> > > > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> > > >> > > > >> > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > > > > _______________________________________________> > > > 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> > >> >> > > _________________________________________________________________> > Windows > Live? Hotmail(R)?more than just e-mail.> >> > > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009> > > _______________________________________________> > 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> > _________________________________________________________________ > Windows Live?: E-mail. Chat. Share. Get more ways to connect. > > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Sat Jan 31 10:54:58 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 11:54:58 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: the contacts table has 24 fields id first_name last_name etc.., I want every single record and field from that table.the contacts_org_types table has three fields id organization_type and internal, I want only the organization_type field from that table, so , I *believe* that i should see 25 fields in my result 24 from table 1 and 1 from table 2- thanks Jean-Paul Natola > From: markamatte at hotmail.com> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 12:49:06 +0000> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > > I hate to make assumptions...but the subject says 'newbie'...and Francisco suggested the fields to join on...not Jean Paul.> > Jean Paul, what fields from each table are you trying to join on(the actual field names)? > > If the example below was used 'as is' and there is an 'ID' field in each table but its not the relationship between these two tables...won't give the results.> > As long as I am 'assuming'...I think the scenario might be a translation table...and the first attemp produced a cartesian join(no joins) and listed each contact having every kind of cust_org_types...so the confusion might be what fields to join on.> > Francisco's Example modified:> > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.cust_org_types = cot.id> > I'm guessing there is a cust_org_types field in the contacts table...and there is a value that needs to be translated?> > If I am off target...please let me know.> > Thanks,> >> _________________________________________________________________ Hotmail? goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 From jnatola at hotmail.com Sat Jan 31 12:00:21 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 13:00:21 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: didnt work with the brackets [] either Jean-Paul Natola > Date: Sat, 31 Jan 2009 08:48:34 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > the join criteria I specified was:> ON ctcs.ID = cot.id> > so ID should match ID based off his example> > maybe add brakets around this field ie, ctcs.[ID] = cot.[ID]> > > -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Sat, Jan 31, 2009 at 4:49 AM, Mark A Matte wrote:> > >> > I hate to make assumptions...but the subject says 'newbie'...and Francisco> > suggested the fields to join on...not Jean Paul.> >> > Jean Paul, what fields from each table are you trying to join on(the actual> > field names)?> >> > If the example below was used 'as is' and there is an 'ID' field in each> > table but its not the relationship between these two tables...won't give the> > results. _________________________________________________________________ Windows Live?: E-mail. Chat. Share. Get more ways to connect. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009 From fhtapia at gmail.com Sat Jan 31 12:05:55 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Sat, 31 Jan 2009 10:05:55 -0800 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: Jean-Paul, I guess I misunderstood you a bit on what you were trying to achieve. let's change the terminology a little bit so that we're all talking the same language, A field is also known as a column so that would be ID, First_name, Last_name, the results are rows... so you are receiving 24 rows with the fields ID, First_name, Last_name, email in order to know what to join by, can you do a select of the 2nd table and let me know the field names? select * from contacts_organization_types -Francisco http://sqlthis.blogspot.com | Tsql and More... On Sat, Jan 31, 2009 at 8:54 AM, jean-paul wrote: > > the contacts table has 24 fields id first_name last_name etc.., I want > every single record and field from that table.the contacts_org_types table > has three fields id organization_type and internal, I want only the > organization_type field from that table, so , I *believe* that i should see > 25 fields in my result 24 from table 1 and 1 from table 2- thanks > Jean-Paul Natola > From: markamatte at hotmail.com> To: > dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 12:49:06 +0000> > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > > I > hate to make assumptions...but the subject says 'newbie'...and Francisco > suggested the fields to join on...not Jean Paul.> > Jean Paul, what fields > from each table are you trying to join on(the actual field names)? > > If > the example below was used 'as is' and there is an 'ID' field in each table > but its not the relationship between these two tables...won't give the > results.> > As long as I am 'assuming'...I think the scenario might be a > translation table...and the first attemp produced a cartesian join(no joins) > and listed each contact having every kind of cust_org_types...so the > confusion might be what fields to join on.> > Francisco's Example modified:> > > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS > cot ON ctcs.cust_org_types = cot.id> > I'm guessing there is a > cust_org_types field in the contacts table...and there is a value that needs > to be translated?> > If I am off target...please let me know.> > Thanks,> >> > _________________________________________________________________ > Hotmail(R) goes where you go. On a PC, on the Web, on your phone. > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Sat Jan 31 12:09:56 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 13:09:56 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: SELECT * FROM contacts_organization_typesLIMIT 0 , 30 id organization_type internal_only Jean-Paul Natola > Date: Sat, 31 Jan 2009 10:05:55 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Jean-Paul,> I guess I misunderstood you a bit on what you were trying to achieve.> let's change the terminology a little bit so that we're all talking the same> language,> > A field is also known as a column so that would be ID, First_name,> Last_name, the results are rows... so you are receiving 24 rows with the> fields ID, First_name, Last_name, email> > in order to know what to join by, can you do a select of the 2nd table and> let me know the field names?> > select * from contacts_organization_types> -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Sat, Jan 31, 2009 at 8:54 AM, jean-paul wrote:> > >> > the contacts table has 24 fields id first_name last_name etc.., I want> > every single record and field from that table.the contacts_org_types table> > has three fields id organization_type and internal, I want only the> > organization_type field from that table, so , I *believe* that i should see> > 25 fields in my result 24 from table 1 and 1 from table 2- thanks> > Jean-Paul Natola > From: markamatte at hotmail.com> To:> > dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 12:49:06 +0000>> > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > > I> > hate to make assumptions...but the subject says 'newbie'...and Francisco> > suggested the fields to join on...not Jean Paul.> > Jean Paul, what fields> > from each table are you trying to join on(the actual field names)? > > If> > the example below was used 'as is' and there is an 'ID' field in each table> > but its not the relationship between these two tables...won't give the> > results.> > As long as I am 'assuming'...I think the scenario might be a> > translation table...and the first attemp produced a cartesian join(no joins)> > and listed each contact having every kind of cust_org_types...so the> > confusion might be what fields to join on.> > Francisco's Example modified:>> > > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS> > cot ON ctcs.cust_org_types = cot.id> > I'm guessing there is a> > cust_org_types field in the contacts table...and there is a value that needs> > to be translated?> > If I am off target...please let me know.> > Thanks,> >>> > _________________________________________________________________> > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > _______________________________________________> > 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> _________________________________________________________________ Hotmail? goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 From jnatola at hotmail.com Sat Jan 31 15:56:21 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 16:56:21 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: So I read about 50 webpages and decided to try this statement SELECT *FROM contacts, contacts_organization_typesWHERE contacts.id = contacts_organization_types.id and still empty results Jean-Paul Natola > Date: Sat, 31 Jan 2009 10:05:55 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Jean-Paul,> I guess I misunderstood you a bit on what you were trying to achieve.> let's change the terminology a little bit so that we're all talking the same> language,> > A field is also known as a column so that would be ID, First_name,> Last_name, the results are rows... so you are receiving 24 rows with the> fields ID, First_name, Last_name, email> > in order to know what to join by, can you do a select of the 2nd table and> let me know the field names?> > select * from contacts_organization_types> -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Sat, Jan 31, 2009 at 8:54 AM, jean-paul wrote:> > >> > the contacts table has 24 fields id first_name last_name etc.., I want> > every single record and field from that table.the contacts_org_types table> > has three fields id organization_type and internal, I want only the> > organization_type field from that table, so , I *believe* that i should see> > 25 fields in my result 24 from table 1 and 1 from table 2- thanks> > Jean-Paul Natola > From: markamatte at hotmail.com> To:> > dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 12:49:06 +0000>> > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > > I> > hate to make assumptions...but the subject says 'newbie'...and Francisco> > suggested the fields to join on...not Jean Paul.> > Jean Paul, what fields> > from each table are you trying to join on(the actual field names)? > > If> > the example below was used 'as is' and there is an 'ID' field in each table> > but its not the relationship between these two tables...won't give the> > results.> > As long as I am 'assuming'...I think the scenario might be a> > translation table...and the first attemp produced a cartesian join(no joins)> > and listed each contact having every kind of cust_org_types...so the> > confusion might be what fields to join on.> > Francisco's Example modified:>> > > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS> > cot ON ctcs.cust_org_types = cot.id> > I'm guessing there is a> > cust_org_types field in the contacts table...and there is a value that needs> > to be translated?> > If I am off target...please let me know.> > Thanks,> >>> > _________________________________________________________________> > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > _______________________________________________> > 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> _________________________________________________________________ Windows Live?: E-mail. Chat. Share. Get more ways to connect. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009 From fhtapia at gmail.com Sat Jan 31 15:57:26 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Sat, 31 Jan 2009 13:57:26 -0800 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: so is the ID value for each row in contacts_organization_types = 1 for each row? this maybe why you get all the organization types as discussed earlier. you will need a unique identifing value between the contacts table and the contacts_organization_types. what you want to do is join the values between your contacts table with a related field in your contacts_organization_types table. that is... your contacts_organization_types table requires an additional field OR... you need a more meaningful value for the id field in the contacts_organization_types table. so let's assume that your first row in your contacts table is: id first name last name email 1 jp natola and let's assume that the corresponding value for this row in contacts_organization_type is NGO. Then you will need a value in the contacts_organization_table that can join the value from your contacts table to just give you a single row from the contacts_organization_type table. Generally I start with a contacts table and follow with a organization type table, the Organiztion type table contains a pkid field that is set as the identity value and is auto-incrementing. likewise I have the same setup for the contacts table. then I build a 3rd junction table that joins the values from the contacts table to the values in the organization type table thus my junction table looks like so: PKID FKContactID FKOrgTypeID this table contains the ID from the contacts table in FKContactID and the the ID from the Organization Table in field FKOrgTypeID. Thus my new select statment would look more like this: SELECT ctc.*, cot.orgtypename, FROM Contacts AS ctc INNER JOIN ContactsOrgJunct AS COJ on ctc.ID = COJ.FKContactID INNER JOIN Contacts_organization_Type AS COT on COJ.FKOrgTypeID = COT.ID the Junction table must be updated with each corresponding organization type field so that you have proper results... I hope this is more clear -Francisco http://sqlthis.blogspot.com | Tsql and More... On Sat, Jan 31, 2009 at 10:09 AM, jean-paul wrote: > > SELECT * FROM contacts_organization_typesLIMIT 0 , 30 > > id organization_type internal_only Jean-Paul Natola > Date: > Sat, 31 Jan 2009 10:05:55 -0800> From: fhtapia at gmail.com> To: > dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie > needs help with select statement> > Jean-Paul,> I guess I misunderstood you > a bit on what you were trying to achieve.> let's change the terminology a > little bit so that we're all talking the same> language,> > A field is also > known as a column so that would be ID, First_name,> Last_name, the results > are rows... so you are receiving 24 rows with the> fields ID, First_name, > Last_name, email> > in order to know what to join by, can you do a select of > the 2nd table and> let me know the field names?> > select * from > contacts_organization_types> -Francisco> http://sqlthis.blogspot.com | > Tsql and More...> > > On Sat, Jan 31, 2009 at 8:54 AM, jean-paul < > jnatola at hotmail.com> wrote:> > >> > the contacts table has 24 fields id > first_name last_name etc.., I want> > every single record and field from > that table.the contacts_org_types table> > has three fields id > organization_type and internal, I want only the> > organization_type field > from that table, so , I *believe* that i should see> > 25 fields in my > result 24 from table 1 and 1 from table 2- thanks> > Jean-Paul Natola > > From: markamatte at hotmail.com> To:> > dba-sqlserver at databaseadvisors.com> > Date: Sat, 31 Jan 2009 12:49:06 +0000>> > Subject: Re: [dba-SQLServer] > Newbie needs help with select statement> > > I> > hate to make > assumptions...but the subject says 'newbie'...and Francisco> > suggested the > fields to join on...not Jean Paul.> > Jean Paul, what fields> > from each > table are you trying to join on(the actual field names)? > > If> > the > example below was used 'as is' and there is an 'ID' field in each table> > > but its not the relationship between these two tables...won't give the> > > results.> > As long as I am 'assuming'...I think the scenario might be a> > > translation table...and the first attemp produced a cartesian join(no > joins)> > and listed each contact having every kind of cust_org_types...so > the> > confusion might be what fields to join on.> > Francisco's Example > modified:>> > > SELECT * FROM contacts AS ctcs> INNER JOIN > contacts_organization_types AS> > cot ON ctcs.cust_org_types = cot.id> > > I'm guessing there is a> > cust_org_types field in the contacts table...and > there is a value that needs> > to be translated?> > If I am off > target...please let me know.> > Thanks,> >>> > > _________________________________________________________________> > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > > _______________________________________________> > 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> > _________________________________________________________________ > Hotmail(R) goes where you go. On a PC, on the Web, on your phone. > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From fhtapia at gmail.com Sat Jan 31 15:58:50 2009 From: fhtapia at gmail.com (Francisco Tapia) Date: Sat, 31 Jan 2009 13:58:50 -0800 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: Because of Sql Server standards, try to stick to Joins made with the INNER / LEFT / FULL / OUTER keywords (see books Online). Joins made at the where clause do work but may have sporadic results that are not consistent. -Francisco http://sqlthis.blogspot.com | Tsql and More... On Sat, Jan 31, 2009 at 1:56 PM, jean-paul wrote: > > So I read about 50 webpages and decided to try this statement > > SELECT *FROM contacts, contacts_organization_typesWHERE contacts.id = > contacts_organization_types.id > > and still empty results > > > Jean-Paul Natola > Date: Sat, 31 Jan 2009 10:05:55 -0800> From: > fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: > [dba-SQLServer] Newbie needs help with select statement> > Jean-Paul,> I > guess I misunderstood you a bit on what you were trying to achieve.> let's > change the terminology a little bit so that we're all talking the same> > language,> > A field is also known as a column so that would be ID, > First_name,> Last_name, the results are rows... so you are receiving 24 rows > with the> fields ID, First_name, Last_name, email> > in order to know what > to join by, can you do a select of the 2nd table and> let me know the field > names?> > select * from contacts_organization_types> -Francisco> > http://sqlthis.blogspot.com | Tsql and More...> > > On Sat, Jan 31, 2009 > at 8:54 AM, jean-paul wrote:> > >> > the contacts > table has 24 fields id first_name last_name etc.., I want> > every single > record and field from that table.the contacts_org_types table> > has three > fields id organization_type and internal, I want only the> > > organization_type field from that table, so , I *believe* that i should see> > > 25 fields in my result 24 from table 1 and 1 from table 2- thanks> > > Jean-Paul Natola > From: markamatte at hotmail.com> To:> > > dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 12:49:06 > +0000>> > Subject: Re: [dba-SQLServer] Newbie needs help with select > statement> > > I> > hate to make assumptions...but the subject says > 'newbie'...and Francisco> > suggested the fields to join on...not Jean > Paul.> > Jean Paul, what fields> > from each table are you trying to join > on(the actual field names)? > > If> > the example below was used 'as is' and > there is an 'ID' field in each table> > but its not the relationship between > these two tables...won't give the> > results.> > As long as I am > 'assuming'...I think the scenario might be a> > translation table...and the > first attemp produced a cartesian join(no joins)> > and listed each contact > having every kind of cust_org_types...so the> > confusion might be what > fields to join on.> > Francisco's Example modified:>> > > SELECT * FROM > contacts AS ctcs> INNER JOIN contacts_organization_types AS> > cot ON > ctcs.cust_org_types = cot.id> > I'm guessing there is a> > cust_org_types > field in the contacts table...and there is a value that needs> > to be > translated?> > If I am off target...please let me know.> > Thanks,> >>> > > _________________________________________________________________> > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> > > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > > _______________________________________________> > 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> > _________________________________________________________________ > Windows Live?: E-mail. Chat. Share. Get more ways to connect. > > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009 > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From jnatola at hotmail.com Sat Jan 31 16:20:11 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 17:20:11 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: value is differnt in con_org_typ id org_typ internal 804 NGO Y 805 EDU N 806 MED Y 807 DON Y and in the the tables the primakary key is id Jean-Paul Natola > Date: Sat, 31 Jan 2009 13:57:26 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > so is the ID value for each row in contacts_organization_types = 1 for each> row?> > this maybe why you get all the organization types as discussed earlier. you> will need a unique identifing value between the contacts table and the> contacts_organization_types.> > what you want to do is join the values between your contacts table with a> related field in your contacts_organization_types table. that is... your> contacts_organization_types table requires an additional field OR... you> need a more meaningful value for the id field in the> contacts_organization_types table.> > so let's assume that your first row in your contacts table is:> id first name last name email> 1 jp natola> > and let's assume that the corresponding value for this row in> contacts_organization_type is NGO.> > Then you will need a value in the contacts_organization_table that can join> the value from your contacts table to just give you a single row from the> contacts_organization_type table.> > Generally I start with a contacts table and follow with a organization type> table, the Organiztion type table contains a pkid field that is set as the> identity value and is auto-incrementing. likewise I have the same setup for> the contacts table. then I build a 3rd junction table that joins the values> from the contacts table to the values in the organization type table thus my> junction table looks like so:> > PKID> FKContactID> FKOrgTypeID> > this table contains the ID from the contacts table in FKContactID and the> the ID from the Organization Table in field FKOrgTypeID.> > Thus my new select statment would look more like this:> > SELECT ctc.*, cot.orgtypename,> FROM Contacts AS ctc> INNER JOIN ContactsOrgJunct AS COJ on ctc.ID = COJ.FKContactID> INNER JOIN Contacts_organization_Type AS COT on COJ.FKOrgTypeID = COT.ID> > the Junction table must be updated with each corresponding organization type> field so that you have proper results...> > I hope this is more clear> > > -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Sat, Jan 31, 2009 at 10:09 AM, jean-paul wrote:> > >> > SELECT * FROM contacts_organization_typesLIMIT 0 , 30> >> > id organization_type internal_only Jean-Paul Natola > Date:> > Sat, 31 Jan 2009 10:05:55 -0800> From: fhtapia at gmail.com> To:> > dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie> > needs help with select statement> > Jean-Paul,> I guess I misunderstood you> > a bit on what you were trying to achieve.> let's change the terminology a> > little bit so that we're all talking the same> language,> > A field is also> > known as a column so that would be ID, First_name,> Last_name, the results> > are rows... so you are receiving 24 rows with the> fields ID, First_name,> > Last_name, email> > in order to know what to join by, can you do a select of> > the 2nd table and> let me know the field names?> > select * from> > contacts_organization_types> -Francisco> http://sqlthis.blogspot.com |> > Tsql and More...> > > On Sat, Jan 31, 2009 at 8:54 AM, jean-paul <> > jnatola at hotmail.com> wrote:> > >> > the contacts table has 24 fields id> > first_name last_name etc.., I want> > every single record and field from> > that table.the contacts_org_types table> > has three fields id> > organization_type and internal, I want only the> > organization_type field> > from that table, so , I *believe* that i should see> > 25 fields in my> > result 24 from table 1 and 1 from table 2- thanks> > Jean-Paul Natola >> > From: markamatte at hotmail.com> To:> > dba-sqlserver at databaseadvisors.com>> > Date: Sat, 31 Jan 2009 12:49:06 +0000>> > Subject: Re: [dba-SQLServer]> > Newbie needs help with select statement> > > I> > hate to make> > assumptions...but the subject says 'newbie'...and Francisco> > suggested the> > fields to join on...not Jean Paul.> > Jean Paul, what fields> > from each> > table are you trying to join on(the actual field names)? > > If> > the> > example below was used 'as is' and there is an 'ID' field in each table> >> > but its not the relationship between these two tables...won't give the> >> > results.> > As long as I am 'assuming'...I think the scenario might be a> >> > translation table...and the first attemp produced a cartesian join(no> > joins)> > and listed each contact having every kind of cust_org_types...so> > the> > confusion might be what fields to join on.> > Francisco's Example> > modified:>> > > SELECT * FROM contacts AS ctcs> INNER JOIN> > contacts_organization_types AS> > cot ON ctcs.cust_org_types = cot.id> >> > I'm guessing there is a> > cust_org_types field in the contacts table...and> > there is a value that needs> > to be translated?> > If I am off> > target...please let me know.> > Thanks,> >>> >> > _________________________________________________________________> >> > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208>> > > _______________________________________________> > 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>> > _________________________________________________________________> > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > _______________________________________________> > 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> _________________________________________________________________ Windows Live? Hotmail?:?more than just e-mail. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_explore_012009 From ab-mi at post3.tele.dk Sat Jan 31 16:58:09 2009 From: ab-mi at post3.tele.dk (Asger Blond) Date: Sat, 31 Jan 2009 23:58:09 +0100 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: Message-ID: <000001c983f7$63062e40$2301a8c0@AB> Francisco may be is right about a third junction table between your contacts and contacts_organization_types tables. But perhaps it's more simple that that. You told us the tree fieldnames of your contacts_organization_types table (id, organization_type, and internal_only) but you didn't tell us all names of the 24 fields in your contacts table. My question is: do your contacts table have a field named something like "organization_type_id"? In that case you might have a simple one-to-many relationship and your query would be something like: SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs INNER JOIN contacts_organization_types AS cot ON ctcs.organization_type_id = cot.id Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul Sendt: 31. januar 2009 23:20 Til: dba-sqlserver at databaseadvisors.com Emne: Re: [dba-SQLServer] Newbie needs help with select statement value is differnt in con_org_typ id org_typ internal 804 NGO Y 805 EDU N 806 MED Y 807 DON Y and in the the tables the primakary key is id Jean-Paul Natola > Date: Sat, 31 Jan 2009 13:57:26 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > so is the ID value for each row in contacts_organization_types = 1 for each> row?> > this maybe why you get all the organization types as discussed earlier. you> will need a unique identifing value between the contacts table and the> contacts_organization_types.> > what you want to do is join the values between your contacts table with a> related field in your contacts_organization_types table. that is... your> contacts_organization_types table requires an additional field OR... you> need a more meaningful value for the id field in the> contacts_organization_types table.> > so let's assume that your first row in your contacts table is:> id first name last name email> 1 jp natola> > and let's assume that the corresponding value for this row in> contacts_organization_type is NGO.> > Then you will need a value in the contacts_organization_table that can join> the value from your contacts table to just give you a single row from the> contacts_organization_type table.> > Generally I start with a contacts table and follow with a organization type> table, the Organiztion type table contains a pkid field that is set as the> identity value and is auto-incrementing. likewise I have the same setup for> the contacts table. then I build a 3rd junction table that joins the values> from the contacts table to the values in the organization type table thus my> junction table looks like so:> > PKID> FKContactID> FKOrgTypeID> > this table contains the ID from the contacts table in FKContactID and the> the ID from the Organization Table in field FKOrgTypeID.> > Thus my new select statment would look more like this:> > SELECT ctc.*, cot.orgtypename,> FROM Contacts AS ctc> INNER JOIN ContactsOrgJunct AS COJ on ctc.ID = COJ.FKContactID> INNER JOIN Contacts_organization_Type AS COT on COJ.FKOrgTypeID = COT.ID> > the Junction table must be updated with each corresponding organization type> field so that you have proper results...> > I hope this is more clear> > > -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Sat, Jan 31, 2009 at 10:09 AM, jean-paul wrote:> > >> > SELECT * FROM contacts_organization_typesLIMIT 0 , 30> >> > id organization_type internal_only Jean-Paul Natola > Date:> > Sat, 31 Jan 2009 10:05:55 -0800> From: fhtapia at gmail.com> To:> > dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie> > needs help with select statement> > Jean-Paul,> I guess I misunderstood you> > a bit on what you were trying to achieve.> let's change the terminology a> > little bit so that we're all talking the same> language,> > A field is also> > known as a column so that would be ID, First_name,> Last_name, the results> > are rows... so you are receiving 24 rows with the> fields ID, First_name,> > Last_name, email> > in order to know what to join by, can you do a select of> > the 2nd table and> let me know the field names?> > select * from> > contacts_organization_types> -Francisco> http://sqlthis.blogspot.com |> > Tsql and More...> > > On Sat, Jan 31, 2009 at 8:54 AM, jean-paul <> > jnatola at hotmail.com> wrote:> > >> > the contacts table has 24 fields id> > first_name last_name etc.., I want> > every single record and field from> > that table.the contacts_org_types table> > has three fields id> > organization_type and internal, I want only the> > organization_type field> > from that table, so , I *believe* that i should see> > 25 fields in my> > result 24 from table 1 and 1 from table 2- thanks> > Jean-Paul Natola >> > From: markamatte at hotmail.com> To:> > dba-sqlserver at databaseadvisors.com>> > Date: Sat, 31 Jan 2009 12:49:06 +0000>> > Subject: Re: [dba-SQLServer]> > Newbie needs help with select statement> > > I> > hate to make> > assumptions...but the subject says 'newbie'...and Francisco> > suggested the> > fields to join on...not Jean Paul.> > Jean Paul, what fields> > from each> > table are you trying to join on(the actual field names)? > > If> > the> > example below was used 'as is' and there is an 'ID' field in each table> >> > but its not the relationship between these two tables...won't give the> >> > results.> > As long as I am 'assuming'...I think the scenario might be a> >> > translation table...and the first attemp produced a cartesian join(no> > joins)> > and listed each contact having every kind of cust_org_types...so> > the> > confusion might be what fields to join on.> > Francisco's Example> > modified:>> > > SELECT * FROM contacts AS ctcs> INNER JOIN> > contacts_organization_types AS> > cot ON ctcs.cust_org_types = cot.id> >> > I'm guessing there is a> > cust_org_types field in the contacts table...and> > there is a value that needs> > to be translated?> > If I am off> > target...please let me know.> > Thanks,> >>> >> > _________________________________________________________________> >> > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TX T_TAGHM_WL_HM_versatility_121208>> > > _______________________________________________> > 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>> > _________________________________________________________________> > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TX T_TAGHM_WL_HM_versatility_121208> > _______________________________________________> > 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> _________________________________________________________________ Windows Live? Hotmail?: more than just e-mail. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_explore _012009 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From jnatola at hotmail.com Sat Jan 31 17:10:38 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 18:10:38 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: <000001c983f7$63062e40$2301a8c0@AB> References: <000001c983f7$63062e40$2301a8c0@AB> Message-ID: the contacts table does NOT have organization type- it has id, first, last, add , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing regarding organization type- I will try you code and let you know- if been on this for the last 30 hours racking my brain- on a good note i read and learned alot since yesterday btw, I'm using MySQL and doing this via phpMyAdmin- if it makes any difference Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 23:58:09 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Francisco may be is right about a third junction table between your contacts> and contacts_organization_types tables. But perhaps it's more simple that> that.> > You told us the tree fieldnames of your contacts_organization_types table> (id, organization_type, and internal_only) but you didn't tell us all names> of the 24 fields in your contacts table.> > My question is: do your contacts table have a field named something like> "organization_type_id"?> > In that case you might have a simple one-to-many relationship and your query> would be something like:> > SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.organization_type_id> = cot.id _________________________________________________________________ Windows Live? Hotmail??more than just e-mail. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009 From ab-mi at post3.tele.dk Sat Jan 31 17:45:24 2009 From: ab-mi at post3.tele.dk (Asger Blond) Date: Sun, 1 Feb 2009 00:45:24 +0100 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: Message-ID: <000101c983fd$fcfe2b50$2301a8c0@AB> Jean-Paul, In that case I guess Francisco is right: you have a so called "many-to-many relationship" comprising tree table: contacts -> "junctiontable" <- contacts_organization_types. What you need is find the name of this "junctiontable" in your database (I know this is easier to say than to do...) If you find a table in your databases which seems to be a link between your contacts and contacts_organization_types table then please tell, and be sure someone on this list will escort you the rest of the way. Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul Sendt: 1. februar 2009 00:11 Til: dba-sqlserver at databaseadvisors.com Emne: Re: [dba-SQLServer] Newbie needs help with select statement the contacts table does NOT have organization type- it has id, first, last, add , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing regarding organization type- I will try you code and let you know- if been on this for the last 30 hours racking my brain- on a good note i read and learned alot since yesterday btw, I'm using MySQL and doing this via phpMyAdmin- if it makes any difference Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 23:58:09 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Francisco may be is right about a third junction table between your contacts> and contacts_organization_types tables. But perhaps it's more simple that> that.> > You told us the tree fieldnames of your contacts_organization_types table> (id, organization_type, and internal_only) but you didn't tell us all names> of the 24 fields in your contacts table.> > My question is: do your contacts table have a field named something like> "organization_type_id"?> > In that case you might have a simple one-to-many relationship and your query> would be something like:> > SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.organization_type_id> = cot.id _________________________________________________________________ Windows Live? Hotmail? more than just e-mail. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howi tworks_012009 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From jnatola at hotmail.com Sat Jan 31 18:22:00 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 19:22:00 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: <000101c983fd$fcfe2b50$2301a8c0@AB> References: <000101c983fd$fcfe2b50$2301a8c0@AB> Message-ID: ok there is a table called switboard with 731,000 and i *think* it maybe it the fields are; id table_left table_left_id table_right table_right_id 402611 contacts 226946 contacts_organization_types 726 is this what i need? Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sun, 1 Feb 2009 00:45:24 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Jean-Paul,> > In that case I guess Francisco is right: you have a so called "many-to-many> relationship" comprising tree table: contacts -> "junctiontable" <-> contacts_organization_types.> What you need is find the name of this "junctiontable" in your database (I> know this is easier to say than to do...)> If you find a table in your databases which seems to be a link between your> contacts and contacts_organization_types table then please tell, and be sure> someone on this list will escort you the rest of the way.> > Asger> > -----Oprindelig meddelelse-----> Fra: dba-sqlserver-bounces at databaseadvisors.com> [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul> Sendt: 1. februar 2009 00:11> Til: dba-sqlserver at databaseadvisors.com> Emne: Re: [dba-SQLServer] Newbie needs help with select statement> > > the contacts table does NOT have organization type- it has id, first, last,> add , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing> regarding organization type- I will try you code and let you know- if been> on this for the last 30 hours racking my brain- on a good note i read and> learned alot since yesterday btw, I'm using MySQL and doing this via> phpMyAdmin- if it makes any difference Jean-Paul Natola > From:> ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31> Jan 2009 23:58:09 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with> select statement> > Francisco may be is right about a third junction table> between your contacts> and contacts_organization_types tables. But perhaps> it's more simple that> that.> > You told us the tree fieldnames of your> contacts_organization_types table> (id, organization_type, and> internal_only) but you didn't tell us all names> of the 24 fields in your> contacts table.> > My question is: do your contacts table have a field named> something like> "organization_type_id"?> > In that case you might have a> simple one-to-many relationship and your query> would be something like:> >> SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER JOIN> contacts_organization_types AS cot ON ctcs.organization_type_id> = cot.id> _________________________________________________________________> Windows Live? Hotmail??more than just e-mail. > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howi> tworks_012009> _______________________________________________> 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> _________________________________________________________________ Hotmail? goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 From jnatola at hotmail.com Sat Jan 31 18:34:15 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 19:34:15 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: <000101c983fd$fcfe2b50$2301a8c0@AB> References: <000101c983fd$fcfe2b50$2301a8c0@AB> Message-ID: there are also sets of tables with the same name with a _seq attached to the name i.e. contacts_seq contacts_organization_types_seq Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sun, 1 Feb 2009 00:45:24 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Jean-Paul,> > In that case I guess Francisco is right: you have a so called "many-to-many> relationship" comprising tree table: contacts -> "junctiontable" <-> contacts_organization_types.> What you need is find the name of this "junctiontable" in your database (I> know this is easier to say than to do...)> If you find a table in your databases which seems to be a link between your> contacts and contacts_organization_types table then please tell, and be sure> someone on this list will escort you the rest of the way.> > Asger> > -----Oprindelig meddelelse-----> Fra: dba-sqlserver-bounces at databaseadvisors.com> [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul> Sendt: 1. februar 2009 00:11> Til: dba-sqlserver at databaseadvisors.com> Emne: Re: [dba-SQLServer] Newbie needs help with select statement> > > the contacts table does NOT have organization type- it has id, first, last,> add , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing> regarding organization type- I will try you code and let you know- if been> on this for the last 30 hours racking my brain- on a good note i read and> learned alot since yesterday btw, I'm using MySQL and doing this via> phpMyAdmin- if it makes any difference Jean-Paul Natola > From:> ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31> Jan 2009 23:58:09 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with> select statement> > Francisco may be is right about a third junction table> between your contacts> and contacts_organization_types tables. But perhaps> it's more simple that> that.> > You told us the tree fieldnames of your> contacts_organization_types table> (id, organization_type, and> internal_only) but you didn't tell us all names> of the 24 fields in your> contacts table.> > My question is: do your contacts table have a field named> something like> "organization_type_id"?> > In that case you might have a> simple one-to-many relationship and your query> would be something like:> >> SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER JOIN> contacts_organization_types AS cot ON ctcs.organization_type_id> = cot.id> _________________________________________________________________> Windows Live? Hotmail??more than just e-mail. > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howi> tworks_012009> _______________________________________________> 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> _________________________________________________________________ Windows Live?: E-mail. Chat. Share. Get more ways to connect. http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009 From ab-mi at post3.tele.dk Sat Jan 31 19:16:05 2009 From: ab-mi at post3.tele.dk (Asger Blond) Date: Sun, 1 Feb 2009 02:16:05 +0100 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: Message-ID: <000001c9840a$a7c89690$2301a8c0@AB> I don't think this is your linking table. A table named "switchboard" (assuming that your "switboard" is a typo) is normally used for managing menus, and you can't be sure that this kind of table will do as a link between your contacts and contacts_organization_type tables. You could try this query (but as said I would look for another possible linking table): SELECT ctc.*, cot.organization_type, FROM contacts AS ctc INNER JOIN switchboard AS swb on ctc.ID = swb.table_left_id INNER JOIN contacts_organization_type AS cot on swb.table_right_id = cot.ID WHERE swb.table_left='contacts' Asger -----Oprindelig meddelelse----- Fra: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul Sendt: 1. februar 2009 01:22 Til: dba-sqlserver at databaseadvisors.com Emne: Re: [dba-SQLServer] Newbie needs help with select statement ok there is a table called switboard with 731,000 and i *think* it maybe it the fields are; id table_left table_left_id table_right table_right_id 402611 contacts 226946 contacts_organization_types 726 is this what i need? Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sun, 1 Feb 2009 00:45:24 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Jean-Paul,> > In that case I guess Francisco is right: you have a so called "many-to-many> relationship" comprising tree table: contacts -> "junctiontable" <-> contacts_organization_types.> What you need is find the name of this "junctiontable" in your database (I> know this is easier to say than to do...)> If you find a table in your databases which seems to be a link between your> contacts and contacts_organization_types table then please tell, and be sure> someone on this list will escort you the rest of the way.> > Asger> > -----Oprindelig meddelelse-----> Fra: dba-sqlserver-bounces at databaseadvisors.com> [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul> Sendt: 1. februar 2009 00:11> Til: dba-sqlserver at databaseadvisors.com> Emne: Re: [dba-SQLServer] Newbie needs help with select statement> > > the contacts table does NOT have organization type- it has id, first, last,> add , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing> regarding organization type- I will try you code and let you know- if been> on this for the last 30 hours racking my brain- on a good note i read and> learned alot since yesterday btw, I'm using MySQL and doing this via> phpMyAdmin- if it makes any difference Jean-Paul Natola > From:> ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31> Jan 2009 23:58:09 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with> select statement> > Francisco may be is right about a third junction table> between your contacts> and contacts_organization_types tables. But perhaps> it's more simple that> that.> > You told us the tree fieldnames of your> contacts_organization_types table> (id, organization_type, and> internal_only) but you didn't tell us all names> of the 24 fields in your> contacts table.> > My question is: do your contacts table have a field named> something like> "organization_type_id"?> > In that case you might have a> simple one-to-many relationship and your query> would be something like:> >> SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER JOIN> contacts_organization_types AS cot ON ctcs.organization_type_id> = cot.id> _________________________________________________________________> Windows Live? Hotmail? more than just e-mail. > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howi > tworks_012009> _______________________________________________> 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> _________________________________________________________________ Hotmail? goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TX T_TAGHM_WL_HM_versatility_121208 _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From jnatola at hotmail.com Sat Jan 31 20:37:01 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 21:37:01 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: <000001c9840a$a7c89690$2301a8c0@AB> References: <000001c9840a$a7c89690$2301a8c0@AB> Message-ID: could it be the _seq tables i was referring to? there are 112 tables What specifially am i looking for in the table they must have both the field contacts and org_type in th same table? Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sun, 1 Feb 2009 02:16:05 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > I don't think this is your linking table.> A table named "switchboard" (assuming that your "switboard" is a typo) is> normally used for managing menus, and you can't be sure that this kind of> table will do as a link between your contacts and contacts_organization_type> tables.> You could try this query (but as said I would look for another possible> linking table):> > SELECT ctc.*, cot.organization_type,> FROM contacts AS ctc> INNER JOIN switchboard AS swb on ctc.ID = swb.table_left_id> INNER JOIN contacts_organization_type AS cot on swb.table_right_id = cot.ID> WHERE swb.table_left='contacts'> > Asger> -----Oprindelig meddelelse-----> Fra: dba-sqlserver-bounces at databaseadvisors.com> [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul> Sendt: 1. februar 2009 01:22> Til: dba-sqlserver at databaseadvisors.com> Emne: Re: [dba-SQLServer] Newbie needs help with select statement> > > ok there is a table called switboard with 731,000 and i *think* it maybe it> the fields are;> > id table_left table_left_id table_right> table_right_id> 402611 contacts 226946 contacts_organization_types 726> > > is this what i need?> > Jean-Paul Natola > From: ab-mi at post3.tele.dk> To:> dba-sqlserver at databaseadvisors.com> Date: Sun, 1 Feb 2009 00:45:24 +0100>> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> >> Jean-Paul,> > In that case I guess Francisco is right: you have a so called> "many-to-many> relationship" comprising tree table: contacts ->> "junctiontable" <-> contacts_organization_types.> What you need is find the> name of this "junctiontable" in your database (I> know this is easier to say> than to do...)> If you find a table in your databases which seems to be a> link between your> contacts and contacts_organization_types table then> please tell, and be sure> someone on this list will escort you the rest of> the way.> > Asger> > -----Oprindelig meddelelse-----> Fra:> dba-sqlserver-bounces at databaseadvisors.com>> [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul>> Sendt: 1. februar 2009 00:11> Til: dba-sqlserver at databaseadvisors.com> Emne:> Re: [dba-SQLServer] Newbie needs help with select statement> > > the> contacts table does NOT have organization type- it has id, first, last,> add> , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing> regarding> organization type- I will try you code and let you know- if been> on this> for the last 30 hours racking my brain- on a good note i read and> learned> alot since yesterday btw, I'm using MySQL and doing this via> phpMyAdmin- if> it makes any difference Jean-Paul Natola > From:> ab-mi at post3.tele.dk> To:> dba-sqlserver at databaseadvisors.com> Date: Sat, 31> Jan 2009 23:58:09 +0100>> Subject: Re: [dba-SQLServer] Newbie needs help with> select statement> >> Francisco may be is right about a third junction table> between your> contacts> and contacts_organization_types tables. But perhaps> it's more> simple that> that.> > You told us the tree fieldnames of your>> contacts_organization_types table> (id, organization_type, and>> internal_only) but you didn't tell us all names> of the 24 fields in your>> contacts table.> > My question is: do your contacts table have a field> named> something like> "organization_type_id"?> > In that case you might> have a> simple one-to-many relationship and your query> would be something> like:> >> SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER> JOIN> contacts_organization_types AS cot ON ctcs.organization_type_id> => cot.id> _________________________________________________________________>> Windows Live? Hotmail??more than just e-mail. >> http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howi> > tworks_012009> _______________________________________________>> 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> > _________________________________________________________________> Hotmail? goes where you go. On a PC, on the Web, on your phone. > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TX> T_TAGHM_WL_HM_versatility_121208 > _______________________________________________> 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> _________________________________________________________________ Windows Live? Hotmail?:?more than just e-mail. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_explore_012009 From stuart at lexacorp.com.pg Sat Jan 31 21:00:23 2009 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Sun, 01 Feb 2009 13:00:23 +1000 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: <000001c9840a$a7c89690$2301a8c0@AB> References: , <000001c9840a$a7c89690$2301a8c0@AB> Message-ID: <49859CE7.7924.DDEE23C@stuart.lexacorp.com.pg> With 731000 rows, I doubt that it's a menu management table as we know it in access. Looking at the field names, I'd guess that it is a link table. Looks like the clown who designed the system built one humungous link table for the whole system rather than using Keys. You'll probably need and additional where clause here: SELECT ctc.*, cot.organization_type, FROM contacts AS ctc INNER JOIN switchboard AS swb on ctc.ID = swb.table_left_id INNER JOIN contacts_organization_type AS cot on swb.table_right_id = cot.ID WHERE swb.table_left='contacts' AND swb.table_right = 'contacts_organization_types' On 1 Feb 2009 at 2:16, Asger Blond wrote: > I don't think this is your linking table. > A table named "switchboard" (assuming that your "switboard" is a typo) is > normally used for managing menus, and you can't be sure that this kind of > table will do as a link between your contacts and contacts_organization_type > tables. > You could try this query (but as said I would look for another possible > linking table): > > SELECT ctc.*, cot.organization_type, > FROM contacts AS ctc > INNER JOIN switchboard AS swb on ctc.ID = swb.table_left_id > INNER JOIN contacts_organization_type AS cot on swb.table_right_id = cot.ID > WHERE swb.table_left='contacts' > > Asger > -----Oprindelig meddelelse----- > Fra: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul > Sendt: 1. februar 2009 01:22 > Til: dba-sqlserver at databaseadvisors.com > Emne: Re: [dba-SQLServer] Newbie needs help with select statement > > > ok there is a table called switboard with 731,000 and i *think* it maybe it > the fields are; > > id table_left table_left_id table_right > table_right_id > 402611 contacts 226946 contacts_organization_types 726 > > > is this what i need? > > Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: > dba-sqlserver at databaseadvisors.com> Date: Sun, 1 Feb 2009 00:45:24 +0100> > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > > Jean-Paul,> > In that case I guess Francisco is right: you have a so called > "many-to-many> relationship" comprising tree table: contacts -> > "junctiontable" <-> contacts_organization_types.> What you need is find the > name of this "junctiontable" in your database (I> know this is easier to say > than to do...)> If you find a table in your databases which seems to be a > link between your> contacts and contacts_organization_types table then > please tell, and be sure> someone on this list will escort you the rest of > the way.> > Asger> > -----Oprindelig meddelelse-----> Fra: > dba-sqlserver-bounces at databaseadvisors.com> > [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul> > Sendt: 1. februar 2009 00:11> Til: dba-sqlserver at databaseadvisors.com> Emne: > Re: [dba-SQLServer] Newbie needs help with select statement> > > the > contacts table does NOT have organization type- it has id, first, last,> add > , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing> regarding > organization type- I will try you code and let you know- if been> on this > for the last 30 hours racking my brain- on a good note i read and> learned > alot since yesterday btw, I'm using MySQL and doing this via> phpMyAdmin- if > it makes any difference Jean-Paul Natola > From:> ab-mi at post3.tele.dk> To: > dba-sqlserver at databaseadvisors.com> Date: Sat, 31> Jan 2009 23:58:09 +0100> > Subject: Re: [dba-SQLServer] Newbie needs help with> select statement> > > Francisco may be is right about a third junction table> between your > contacts> and contacts_organization_types tables. But perhaps> it's more > simple that> that.> > You told us the tree fieldnames of your> > contacts_organization_types table> (id, organization_type, and> > internal_only) but you didn't tell us all names> of the 24 fields in your> > contacts table.> > My question is: do your contacts table have a field > named> something like> "organization_type_id"?> > In that case you might > have a> simple one-to-many relationship and your query> would be something > like:> >> SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER > JOIN> contacts_organization_types AS cot ON ctcs.organization_type_id> = > cot.id> _________________________________________________________________> > Windows LiveTM Hotmail?...more than just e-mail. > > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howi > > tworks_012009> _______________________________________________> > 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> > _________________________________________________________________ > Hotmail? goes where you go. On a PC, on the Web, on your phone. > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TX > T_TAGHM_WL_HM_versatility_121208 > _______________________________________________ > 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 jnatola at hotmail.com Sat Jan 31 21:20:05 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 22:20:05 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: <49859CE7.7924.DDEE23C@stuart.lexacorp.com.pg> References: , <000001c9840a$a7c89690$2301a8c0@AB> <49859CE7.7924.DDEE23C@stuart.lexacorp.com.pg> Message-ID: I thank you for the input , and will attempt your code- and believe me , from what I've heard about the company that designed the website/database CLOWNS is an understatement- > _________________________________________________________________ Hotmail? goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 From jnatola at hotmail.com Sat Jan 31 10:17:59 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 11:17:59 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: References: Message-ID: the contacts table has 24 fields id first_name last_name etc.., I want every single record and field from that table. the contacts_org_types table has three fields id organization_type and internal, I want only the organization_type field from that table, so , I *believe* that i should see 25 fields in my result 24 from table 1 and 1 from table 2- thanks Jean-Paul Natola > From: markamatte at hotmail.com> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 12:49:06 +0000> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > > I hate to make assumptions...but the subject says 'newbie'...and Francisco suggested the fields to join on...not Jean Paul.> > Jean Paul, what fields from each table are you trying to join on(the actual field names)? > > If the example below was used 'as is' and there is an 'ID' field in each table but its not the relationship between these two tables...won't give the results.> > As long as I am 'assuming'...I think the scenario might be a translation table...and the first attemp produced a cartesian join(no joins) and listed each contact having every kind of cust_org_types...so the confusion might be what fields to join on.> > Francisco's Example modified:> > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.cust_org_types = cot.id> > I'm guessing there is a cust_org_types field in the contacts table...and there is a value that needs to be translated?> > If I am off target...please let me know.> > Thanks,> > > Mark A. Matte> Date: Fri, 30 Jan 2009 21:43:12 -0800> From: fhtapia at gmail.com> To: dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > In that case simply omit the Where clause no need to have it if you are not> using it.> > SELECT * FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id> > -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Fri, Jan 30, 2009 at 9:39 PM, jean-paul wrote:> > >> > you flew way over my head on that one-> >> > in the db all contacts have a value in the org type field from the second> > table> >> >> > I want ALL the contacts from the contacts table> > and Im NOT looking for a specific criteria from the contacts_org_tpes I> > just want it to return the value> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> > Jean-Paul Natola> >> >> >> >> >> >> > > Date: Fri, 30 Jan 2009 21:25:49 -0800> > > From: fhtapia at gmail.com> > > To: dba-sqlserver at databaseadvisors.com> > > Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > >> > > Jean Paul,> > > You'll want to define your where criteria... that is:> > >> > > SELECT * FROM contacts AS ctc WHERE NAME = 'Criteria'> > >> > > this way the results are what you expect> > >> > > To join two tables you will want to associate the corresponding fields> > >> > > Such as:> > >> > > SELECT * FROM contacts AS ctcs> > > INNER JOIN contacts_organization_types AS cot ON ctcs.ID = cot.id> > > WHERE ctcs.name = 'Criteria'> > >> > > some interesting things are happening here... first I have used a table> > > alias that's where you see the table name contacts followed by the> > keyword> > > AS then an abbreviation of my liking (no reserved words) such as ctcs> > >> > > so I 'm telling the engine that I will from that point on substitute the> > use> > > of ctcs whenever it expects to see an explicit reference for the table> > name> > > contacts. Also if you take a look at the criteria, you'll notice that I> > > have a field name in there the name I took from your example but it> > should> > > be any valid name in your table that you want to search against... saying> > > WHERE 1 is a true statement, but does not reflect the case of WHERE id => > 1,> > > so you may want to revise your select statement.> > >> > >> > >> > > -Francisco> > > http://sqlthis.blogspot.com | Tsql and More...> > >> > >> > > On Fri, Jan 30, 2009 at 8:58 PM, jean-paul wrote:> > >> > > >> > > > Hi all,> > > >> > > > So I was attempting to for the first time to get data using the select> > > > statment> > > >> > > > here was my first syntax> > > > SELECT * FROM `contacts` WHERE 1> > > >> > > > it returned all the records (as I wanted) 9050 records> > > > contact name address emaill etcc..> > > > now there is another table called contacts_organization_types> > > > I wanted the corresponding output to come out in the same query> > > >> > > > so i tried this> > > > SELECT * FROM `contacts`,`contacts_organization_types` WHERE 1> > > >> > > > now i got the same results as above- but instead of it adding the> > field> > > > to the list it returned each record from the contacts with every single> > > > cust_org_types for example> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > first statement results;> > > >> > > > id first name last name email> > > > 1 jp natola> > > >> > > >> > > > second statment results;> > > >> > > >> > > >> > > > id first name last name email organaization type> > > > 1 jp natola NGO> > > >> > > >> > > > 1 jp natola MED> > > >> > > > 1 jp natola Donor> > > >> > > > 1 jp natola Education> > > >> > > > 1 jp natola Media> > > >> > > > How do i modify the statement to just give me the record with the> > actual> > > > value that is in the contacts record> > > >> > > > thanks> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > _________________________________________________________________> > > > Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> > > >> > > >> > http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208> > > > _______________________________________________> > > > 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> > >> >> > _________________________________________________________________> > Windows Live? Hotmail(R)?more than just e-mail.> >> > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009> > _______________________________________________> > 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> > _________________________________________________________________> Windows Live?: E-mail. Chat. Share. Get more ways to connect. > http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009> _______________________________________________> dba-SQLServer mailing list> dba-SQLServer at databaseadvisors.com> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver> http://www.databaseadvisors.com> _________________________________________________________________ Windows Live?: E-mail. Chat. Share. Get more ways to connect. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_allup_explore_012009 From jnatola at hotmail.com Sat Jan 31 17:08:59 2009 From: jnatola at hotmail.com (jean-paul) Date: Sat, 31 Jan 2009 18:08:59 -0500 Subject: [dba-SQLServer] Newbie needs help with select statement In-Reply-To: <000001c983f7$63062e40$2301a8c0@AB> References: <000001c983f7$63062e40$2301a8c0@AB> Message-ID: the contacts table does NOT have organization type- it has id, first, last, add , cty, st, zip, tel, fax, dte_created, email, etc.. but nothing regarding organization type- I will try you code and let you know- if been on this for the last 30 hours racking my brain- on a good note i read and learned alot since yesterday btw, I'm using MySQL and doing this via phpMyAdmin- if it makes any difference Jean-Paul Natola > From: ab-mi at post3.tele.dk> To: dba-sqlserver at databaseadvisors.com> Date: Sat, 31 Jan 2009 23:58:09 +0100> Subject: Re: [dba-SQLServer] Newbie needs help with select statement> > Francisco may be is right about a third junction table between your contacts> and contacts_organization_types tables. But perhaps it's more simple that> that.> > You told us the tree fieldnames of your contacts_organization_types table> (id, organization_type, and internal_only) but you didn't tell us all names> of the 24 fields in your contacts table.> > My question is: do your contacts table have a field named something like> "organization_type_id"?> > In that case you might have a simple one-to-many relationship and your query> would be something like:> > SELECT ctcs.*, cot.organization_type FROM contacts AS ctcs> INNER JOIN contacts_organization_types AS cot ON ctcs.organization_type_id> = cot.id> > > Asger> -----Oprindelig meddelelse-----> Fra: dba-sqlserver-bounces at databaseadvisors.com> [mailto:dba-sqlserver-bounces at databaseadvisors.com] P? vegne af jean-paul> Sendt: 31. januar 2009 23:20> Til: dba-sqlserver at databaseadvisors.com> Emne: Re: [dba-SQLServer] Newbie needs help with select statement> > > value is differnt in con_org_typ> > id org_typ internal> 804 NGO Y> 805 EDU N> 806 MED Y> 807 DON Y> > > and in the the tables the primakary key is id Jean-Paul Natola >> Date: Sat, 31 Jan 2009 13:57:26 -0800> From: fhtapia at gmail.com> To:> dba-sqlserver at databaseadvisors.com> Subject: Re: [dba-SQLServer] Newbie> needs help with select statement> > so is the ID value for each row in> contacts_organization_types = 1 for each> row?> > this maybe why you get all> the organization types as discussed earlier. you> will need a unique> identifing value between the contacts table and the>> contacts_organization_types.> > what you want to do is join the values> between your contacts table with a> related field in your> contacts_organization_types table. that is... your>> contacts_organization_types table requires an additional field OR... you>> need a more meaningful value for the id field in the>> contacts_organization_types table.> > so let's assume that your first row in> your contacts table is:> id first name last name email> 1 jp natola> > and> let's assume that the corresponding value for this row in>> contacts_organization_type is NGO.> > Then you will need a value in the> contacts_organization_table that can join> the value from your contacts> table to just give you a single row from the> contacts_organization_type> table.> > Generally I start with a contacts table and follow with a> organization type> table, the Organiztion type table contains a pkid field> that is set as the> identity value and is auto-incrementing. likewise I have> the same setup for> the contacts table. then I build a 3rd junction table> that joins the values> from the contacts table to the values in the> organization type table thus my> junction table looks like so:> > PKID>> FKContactID> FKOrgTypeID> > this table contains the ID from the contacts> table in FKContactID and the> the ID from the Organization Table in field> FKOrgTypeID.> > Thus my new select statment would look more like this:> >> SELECT ctc.*, cot.orgtypename,> FROM Contacts AS ctc> INNER JOIN> ContactsOrgJunct AS COJ on ctc.ID = COJ.FKContactID> INNER JOIN> Contacts_organization_Type AS COT on COJ.FKOrgTypeID = COT.ID> > the> Junction table must be updated with each corresponding organization type>> field so that you have proper results...> > I hope this is more clear> > >> -Francisco> http://sqlthis.blogspot.com | Tsql and More...> > > On Sat, Jan> 31, 2009 at 10:09 AM, jean-paul wrote:> > >> > SELECT> * FROM contacts_organization_typesLIMIT 0 , 30> >> > id organization_type> internal_only Jean-Paul Natola > Date:> > Sat, 31 Jan 2009 10:05:55 -0800>> From: fhtapia at gmail.com> To:> > dba-sqlserver at databaseadvisors.com> Subject:> Re: [dba-SQLServer] Newbie> > needs help with select statement> >> Jean-Paul,> I guess I misunderstood you> > a bit on what you were trying to> achieve.> let's change the terminology a> > little bit so that we're all> talking the same> language,> > A field is also> > known as a column so that> would be ID, First_name,> Last_name, the results> > are rows... so you are> receiving 24 rows with the> fields ID, First_name,> > Last_name, email> > in> order to know what to join by, can you do a select of> > the 2nd table and>> let me know the field names?> > select * from> >> contacts_organization_types> -Francisco> http://sqlthis.blogspot.com |> >> Tsql and More...> > > On Sat, Jan 31, 2009 at 8:54 AM, jean-paul <> >> jnatola at hotmail.com> wrote:> > >> > the contacts table has 24 fields id> >> first_name last_name etc.., I want> > every single record and field from> >> that table.the contacts_org_types table> > has three fields id> >> organization_type and internal, I want only the> > organization_type field>> > from that table, so , I *believe* that i should see> > 25 fields in my> >> result 24 from table 1 and 1 from table 2- thanks> > Jean-Paul Natola >> >> From: markamatte at hotmail.com> To:> > dba-sqlserver at databaseadvisors.com>> >> Date: Sat, 31 Jan 2009 12:49:06 +0000>> > Subject: Re: [dba-SQLServer]> >> Newbie needs help with select statement> > > I> > hate to make> >> assumptions...but the subject says 'newbie'...and Francisco> > suggested> the> > fields to join on...not Jean Paul.> > Jean Paul, what fields> > from> each> > table are you trying to join on(the actual field names)? > > If> >> the> > example below was used 'as is' and there is an 'ID' field in each> table> >> > but its not the relationship between these two tables...won't> give the> >> > results.> > As long as I am 'assuming'...I think the scenario> might be a> >> > translation table...and the first attemp produced a> cartesian join(no> > joins)> > and listed each contact having every kind of> cust_org_types...so> > the> > confusion might be what fields to join on.> >> Francisco's Example> > modified:>> > > SELECT * FROM contacts AS ctcs> INNER> JOIN> > contacts_organization_types AS> > cot ON ctcs.cust_org_types => cot.id> >> > I'm guessing there is a> > cust_org_types field in the contacts> table...and> > there is a value that needs> > to be translated?> > If I am> off> > target...please let me know.> > Thanks,> >>> >> >> _________________________________________________________________> >> >> Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> >> >> http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TX> T_TAGHM_WL_HM_versatility_121208>> > >> _______________________________________________> > 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>> >> _________________________________________________________________> >> Hotmail(R) goes where you go. On a PC, on the Web, on your phone.> >> >> http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TX> T_TAGHM_WL_HM_versatility_121208> >> _______________________________________________> > 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> > _________________________________________________________________> Windows Live? Hotmail?:?more than just e-mail. > http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_explore> _012009> _______________________________________________> 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> _________________________________________________________________ Windows Live? Hotmail?:?more than just e-mail. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_explore_012009