From jwcolby at colbyconsulting.com Mon Oct 1 07:03:09 2007 From: jwcolby at colbyconsulting.com (jwcolby) Date: Mon, 1 Oct 2007 08:03:09 -0400 Subject: [dba-SQLServer] Dynamic SQL Message-ID: <00ea01c80423$08fe5030$6c7aa8c0@M90> Folks, There has been much discussion re using dynamic SQL to perform operations on SQL Server, vs. using stored procedures. Let me give you a rundown on my situation and I would then like opinions on strategy. This is the "big database" operations I am discussing. I get DVDs full of raw data, typically many different text (flat or CSV) files, which I assemble into a directory. I am using VB.Net to iterate through the directory and import all of the files into SQL Server. My code: 1) Creates a new database if none exists for this import. 2) Creates a new "master" raw data table if none exists 3) Creates a temp table for each data file 4) Imports the data into the temp table. 5) If the complete data file imports without errors, I append the temp to the master table 6) If the append succeeds I delete the temp table 7) If all of the above succeeds I move the data file to an archive directory 8) I log each step of the above, both errors if any and a general memo of steps, how long they took etc and when done I write that log file to disk. Someday I will write that log data to disk. Steps 1 through 6 is all "dynamic sql" that I build up based on the SQL Server name, the database name, the table names, and even the field names. Doing things this way allows me to have a class that knows how to build databases, tables and indexes, and also perform action queries to perform all of these actions. My question is simply whether this really needs to be moved to the SP paradigm? My database runs on a server here at my office behind a hardware and a software firewall, although of course I am not a notwork guy so in the end how secure it all is is questionable. To this point there is no one accessing the database from outside of my office and in fact to this point I am the only one accessing the database at all. If I were to move to the SP paradigm I guess I would need to design and store all of these SPs into a master database and run them from there, passing in the various part names? I really do not want to go there "today" as I have work to do and this would be another learning curve and a lot of development effort. So, opinions on the necessity in my case? John W. Colby Colby Consulting www.ColbyConsulting.com From accessd at shaw.ca Mon Oct 1 11:51:57 2007 From: accessd at shaw.ca (Jim Lawrence) Date: Mon, 01 Oct 2007 09:51:57 -0700 Subject: [dba-SQLServer] Dynamic SQL In-Reply-To: <00ea01c80423$08fe5030$6c7aa8c0@M90> Message-ID: <13D604023A5947E5895FCCD9F6D6B306@creativesystemdesigns.com> Hi John: When I want to find if a table exists in my database you can run the following code: CREATE PROCEDURE Create MyDatabasetTable AS /* if exist do the following */ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MyDatabasetTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[MyDatabasetTable] else /* create the table */ CREATE TABLE [dbo].[ MyDatabasetTable] ( [ReferenceNumber] [varchar] (10), [Status] [varchar] (2), [Account] [int] NULL, [ClientCode] [char] (10), [InvoiceDate] [varchar] (12), [Amount] [money] NULL, [IDNumber] [varchar] (16), [ExpiryDate] [varchar] (8), [Source] [int] NULL, [Type] [int] NULL, [TransactionID] [varchar] (20), [ProcessCode] [char] (1), [OperatorCode] [char] (8) ) ON [PRIMARY] GO The above example does not make much sense as in why would someone delete a table if found and create if not but this just a code sample. It shows the best way to create and delete tables within an application that is running a MS SQL server. Just call the appropriate stored procedure. HTH Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, October 01, 2007 5:03 AM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Dynamic SQL Folks, There has been much discussion re using dynamic SQL to perform operations on SQL Server, vs. using stored procedures. Let me give you a rundown on my situation and I would then like opinions on strategy. This is the "big database" operations I am discussing. I get DVDs full of raw data, typically many different text (flat or CSV) files, which I assemble into a directory. I am using VB.Net to iterate through the directory and import all of the files into SQL Server. My code: 1) Creates a new database if none exists for this import. 2) Creates a new "master" raw data table if none exists 3) Creates a temp table for each data file 4) Imports the data into the temp table. 5) If the complete data file imports without errors, I append the temp to the master table 6) If the append succeeds I delete the temp table 7) If all of the above succeeds I move the data file to an archive directory 8) I log each step of the above, both errors if any and a general memo of steps, how long they took etc and when done I write that log file to disk. Someday I will write that log data to disk. Steps 1 through 6 is all "dynamic sql" that I build up based on the SQL Server name, the database name, the table names, and even the field names. Doing things this way allows me to have a class that knows how to build databases, tables and indexes, and also perform action queries to perform all of these actions. My question is simply whether this really needs to be moved to the SP paradigm? My database runs on a server here at my office behind a hardware and a software firewall, although of course I am not a notwork guy so in the end how secure it all is is questionable. To this point there is no one accessing the database from outside of my office and in fact to this point I am the only one accessing the database at all. If I were to move to the SP paradigm I guess I would need to design and store all of these SPs into a master database and run them from there, passing in the various part names? I really do not want to go there "today" as I have work to do and this would be another learning curve and a lot of development effort. So, opinions on the necessity in my case? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From Patricia.O'Connor at otda.state.ny.us Mon Oct 1 13:05:19 2007 From: Patricia.O'Connor at otda.state.ny.us (O'Connor, Patricia (OTDA)) Date: Mon, 1 Oct 2007 14:05:19 -0400 Subject: [dba-SQLServer] SQL Server Classes In-Reply-To: <13D604023A5947E5895FCCD9F6D6B306@creativesystemdesigns.com> References: <00ea01c80423$08fe5030$6c7aa8c0@M90> <13D604023A5947E5895FCCD9F6D6B306@creativesystemdesigns.com> Message-ID: <01DBAB52E30A9A4AB3D94EF8029EDBE8021BB018@EXCNYSM0A1AI.nysemail.nyenet> We are switching some fox pro and access dbs to ms sql server 2005 What classes should we take to be able to Designing, implement, and maintaining databases program stored procedures scripts triggers etc and have front end users write queries These were suggested are they decent, should there be others, and what order is best MS 2778: Writing Queries Using Microsoft(r) SQL Server(tm) 2005 Transact-SQL MS 2779: Implementing a Microsoft SQL Server 2005 Database MS 2780: Maintaining a Microsoft SQL Server 2005 Database Thank you Patti ************************************************** * Patricia O'Connor * Associate Computer Programmer Analyst * OTDA - BDMA * (W) mailto:Patricia.O'Connor at otda.state.ny.us * (w) mailto:aa1160 at nysemail.state.ny.us ************************************************** -------------------------------------------------------- This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system. From fuller.artful at gmail.com Mon Oct 1 14:00:12 2007 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 1 Oct 2007 15:00:12 -0400 Subject: [dba-SQLServer] SQL Server Classes In-Reply-To: <01DBAB52E30A9A4AB3D94EF8029EDBE8021BB018@EXCNYSM0A1AI.nysemail.nyenet> References: <00ea01c80423$08fe5030$6c7aa8c0@M90> <13D604023A5947E5895FCCD9F6D6B306@creativesystemdesigns.com> <01DBAB52E30A9A4AB3D94EF8029EDBE8021BB018@EXCNYSM0A1AI.nysemail.nyenet> Message-ID: <29f585dd0710011200w7b3d4681j2fd65dcac326de0c@mail.gmail.com> I have taught the first and third, Patricia. The students's course evaluations were all "excellent". I'm teaching the second one on October 22, but it will be my first time at it. For this I also highly recommend my friend Dejan Sunderic's book "Microsoft SQL Server 2005 Stored Procedure Programming in T-SQL and .NET". He provides a site from which you can download all the examples and the database (which does assets management and is non-trivial. He's got about 3 chapters on using the CLR, too. hth, Arthur On 10/1/07, O'Connor, Patricia (OTDA) wrote: > > We are switching some fox pro and access dbs to ms sql server 2005 > > What classes should we take to be able to > Designing, implement, and maintaining databases > program stored procedures scripts triggers etc > and have front end users write queries > > These were suggested are they decent, should there be others, and what > order is best > > MS 2778: Writing Queries Using Microsoft(r) SQL Server(tm) 2005 > Transact-SQL > MS 2779: Implementing a Microsoft SQL Server 2005 Database > MS 2780: Maintaining a Microsoft SQL Server 2005 Database > > Thank you > Patti > ************************************************** > * Patricia O'Connor > * Associate Computer Programmer Analyst > * OTDA - BDMA > * (W) mailto:Patricia.O'Connor at otda.state.ny.us > * (w) mailto:aa1160 at nysemail.state.ny.us > ************************************************** > -------------------------------------------------------- > This e-mail, including any attachments, may be confidential, privileged or > otherwise legally protected. It is intended only for the addressee. If you > received this e-mail in error or from someone who was not authorized to send > it to you, do not disseminate, copy or otherwise use this e-mail or its > attachments. Please notify the sender immediately by reply e-mail and > delete the e-mail from your system. > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > From Patricia.O'Connor at otda.state.ny.us Mon Oct 1 14:04:51 2007 From: Patricia.O'Connor at otda.state.ny.us (O'Connor, Patricia (OTDA)) Date: Mon, 1 Oct 2007 15:04:51 -0400 Subject: [dba-SQLServer] SQL Server Classes In-Reply-To: <29f585dd0710011200w7b3d4681j2fd65dcac326de0c@mail.gmail.com> References: <00ea01c80423$08fe5030$6c7aa8c0@M90><13D604023A5947E5895FCCD9F6D6B306@creativesystemdesigns.com><01DBAB52E30A9A4AB3D94EF8029EDBE8021BB018@EXCNYSM0A1AI.nysemail.nyenet> <29f585dd0710011200w7b3d4681j2fd65dcac326de0c@mail.gmail.com> Message-ID: <01DBAB52E30A9A4AB3D94EF8029EDBE8021BB01D@EXCNYSM0A1AI.nysemail.nyenet> Arthur Thanks - would that class happened to be in Albany NY 8-) Good luck with your class Which order for these classes is better. ************************************************** * Patricia O'Connor * Associate Computer Programmer Analyst * OTDA - BDMA * (W) mailto:Patricia.O'Connor at otda.state.ny.us * (w) mailto:aa1160 at nysemail.state.ny.us ************************************************** > -------------------------------------------------------- This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system. -----Original Message----- > From: dba-sqlserver-bounces at databaseadvisors.com > [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf > Of Arthur Fuller > Sent: Monday, October 01, 2007 03:00 PM > To: dba-sqlserver at databaseadvisors.com > Subject: Re: [dba-SQLServer] SQL Server Classes > > I have taught the first and third, Patricia. The students's > course evaluations were all "excellent". I'm teaching the > second one on October 22, but it will be my first time at it. > For this I also highly recommend my friend Dejan Sunderic's > book "Microsoft SQL Server 2005 Stored Procedure Programming > in T-SQL and .NET". He provides a site from which you can > download all the examples and the database (which does assets > management and is non-trivial. He's got about 3 chapters on > using the CLR, too. > > hth, > Arthur > > On 10/1/07, O'Connor, Patricia (OTDA) > > wrote: > > > > We are switching some fox pro and access dbs to ms sql server 2005 > > > > What classes should we take to be able to > > Designing, implement, and maintaining databases > > program stored procedures scripts triggers etc > > and have front end users write queries > > > > These were suggested are they decent, should there be > others, and what > > order is best > > > > MS 2778: Writing Queries Using Microsoft(r) SQL Server(tm) 2005 > > Transact-SQL MS 2779: Implementing a Microsoft SQL Server 2005 > > Database MS 2780: Maintaining a Microsoft SQL Server 2005 Database > > > > Thank you > > Patti > > ************************************************** > > * Patricia O'Connor > > * Associate Computer Programmer Analyst > > * OTDA - BDMA > > * (W) mailto:Patricia.O'Connor at otda.state.ny.us > > * (w) mailto:aa1160 at nysemail.state.ny.us > > ************************************************** > > -------------------------------------------------------- > > This e-mail, including any attachments, may be confidential, > > privileged or otherwise legally protected. It is intended > only for the > > addressee. If you received this e-mail in error or from someone who > > was not authorized to send it to you, do not disseminate, copy or > > otherwise use this e-mail or its attachments. Please notify the > > sender immediately by reply e-mail and delete the e-mail > from your system. > > > > > > _______________________________________________ > > 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 Mon Oct 1 14:16:59 2007 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 1 Oct 2007 15:16:59 -0400 Subject: [dba-SQLServer] SQL Server Classes In-Reply-To: <01DBAB52E30A9A4AB3D94EF8029EDBE8021BB01D@EXCNYSM0A1AI.nysemail.nyenet> References: <00ea01c80423$08fe5030$6c7aa8c0@M90> <13D604023A5947E5895FCCD9F6D6B306@creativesystemdesigns.com> <01DBAB52E30A9A4AB3D94EF8029EDBE8021BB018@EXCNYSM0A1AI.nysemail.nyenet> <29f585dd0710011200w7b3d4681j2fd65dcac326de0c@mail.gmail.com> <01DBAB52E30A9A4AB3D94EF8029EDBE8021BB01D@EXCNYSM0A1AI.nysemail.nyenet> Message-ID: <29f585dd0710011216o16a8857dk1a7b1bd1ee056c30@mail.gmail.com> Sorry, Patricia, but not that far. In Toronto, at ProTechTraining.com. If interested, you can contact Robert Stover at rstover at protechtraining.com Arthur On 10/1/07, O'Connor, Patricia (OTDA) wrote: > > Arthur > > Thanks - would that class happened to be in Albany NY 8-) > > Good luck with your class > > Which order for these classes is better. > From jwcolby at colbyconsulting.com Tue Oct 2 07:59:12 2007 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 2 Oct 2007 08:59:12 -0400 Subject: [dba-SQLServer] Bulk insert and table names Message-ID: <015e01c804f4$0851f7a0$6c7aa8c0@M90> You guys will love this one. I am writing .Net stuff to do imports of these huge text files. I fill a directory with files to be imported, then the code gets the file names in that directory and iterates through importing the files. I use the bulk copy object to do the insert. In this case I had files named using the two digit state code by the people who generated the source files. AK.txt AL.txt ... WY.txt I simply stripped off the .txt and use the file name itself as the name of a temp table into which I import the data. Once imported and validated, I then append the temp table to the permanent table and delete the temp table. I log EVERYTHING from the start / stop time of each operation to the error text, how many records successfully imported into the temp table etc. With me so far? My code takes off and runs. I end up with TWO files - IN.txt and OR.txt - that refuse to import. The error message thrown by the Bulk Copy object is "cannot access the destination table". These tables - IN and OR do indeed exist, nothing wrong with them. I have code that builds the tables on-the-fly and the tables are being built but the BulkCopy object cannot append the data into them. After an embarrassingly long period of head scratching, checking that I have sufficient disk space (this is a terabyte array, I have enough space!), compacting the database etc. it finally dawns on me that perhaps the table names are verboten. I changed the name of the input files from IN.txt to IND.txt and OR.txt to ORE.txt and voila, she runs. My best guess at this point is that the Bulk Copy object or something it calls in SQL Server to get its job done views IN and OR as key words and will not allow some operations to be performed on tables named that. Notice that I could execute, using the CMD object in .NET, SQL code to create the tables and THAT worked. Anyway, just another piece of trivia to remember - somewhere in the bowels of SQL Server exists a distaste for table names (and field names as well?) that are the same as key words. Which of course leads us to the question, where is the list of key words that we are not allowed to use? On a related note, I also create and index a PKID in the tables. In fact I quite doing so in the temp tables since it served no useful purpose, however while I was still doing so I ran into an interesting similar problem. I was naming the indexes IX & FieldName, whatever field name might be. Because I always used PKID as my field name, SQL Server complained about the index in the second table I tried to create (I create the permanent and then the temp table). It turns out that the index names appear to be stored in a common collection keyed on the index name and so the second time I tried to create the same name for an index (in a DIFFERENT table) SQL Server threw an error. I ended up using IX & TableName & FieldName as the index name and it worked just fine of course. John W. Colby Colby Consulting www.ColbyConsulting.com From Mwp.Reid at qub.ac.uk Tue Oct 2 08:07:00 2007 From: Mwp.Reid at qub.ac.uk (Martin W Reid) Date: Tue, 2 Oct 2007 14:07:00 +0100 Subject: [dba-SQLServer] Bulk insert and table names In-Reply-To: <015e01c804f4$0851f7a0$6c7aa8c0@M90> References: <015e01c804f4$0851f7a0$6c7aa8c0@M90> Message-ID: Hi John List of SQL 2000 Keywords http://msdn2.microsoft.com/en-us/library/aa238507(SQL.80).aspx Martin Martin Reid Telephone: 02890974465 From jwcolby at colbyconsulting.com Tue Oct 2 09:01:27 2007 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 2 Oct 2007 10:01:27 -0400 Subject: [dba-SQLServer] [AccessD] Bulk insert and table names In-Reply-To: References: <015e01c804f4$0851f7a0$6c7aa8c0@M90> Message-ID: <015f01c804fc$ba890230$6c7aa8c0@M90> LOL. Thanks for that but I suppose my question was a jab at the concept that I would HAVE to make sure that my table / field names did not collide with some list of reserved words inside of SQL Server. The SQL Server programming team should ensure that I can name my tables and fields whatever I want to, NOT look up my proposed table field names in THEIR (ever changing) list of keywords and change my choice if it collides with their reserved words. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Martin W Reid Sent: Tuesday, October 02, 2007 9:07 AM To: dba-sqlserver at databaseadvisors.com; 'Access Developers discussion and problem solving' Subject: Re: [AccessD] [dba-SQLServer] Bulk insert and table names Hi John List of SQL 2000 Keywords http://msdn2.microsoft.com/en-us/library/aa238507(SQL.80).aspx Martin Martin Reid Telephone: 02890974465 -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com From fhtapia at gmail.com Tue Oct 2 10:56:56 2007 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 2 Oct 2007 08:56:56 -0700 Subject: [dba-SQLServer] [AccessD] Bulk insert and table names In-Reply-To: <015f01c804fc$ba890230$6c7aa8c0@M90> References: <015e01c804f4$0851f7a0$6c7aa8c0@M90> <015f01c804fc$ba890230$6c7aa8c0@M90> Message-ID: The thing is that if you bracket your table names, you're allowed to use them, prefixing your table names with something simple such as tblOR or tblIN would have clearly avoided the problem you faced. Similarly with indexes, you've found a great way to keep them unique by including the tablename in the index. On 10/2/07, jwcolby wrote: > > LOL. > > Thanks for that but I suppose my question was a jab at the concept that I > would HAVE to make sure that my table / field names did not collide with > some list of reserved words inside of SQL Server. The SQL Server > programming team should ensure that I can name my tables and fields > whatever > I want to, NOT look up my proposed table field names in THEIR (ever > changing) list of keywords and change my choice if it collides with their > reserved words. > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Martin W Reid > Sent: Tuesday, October 02, 2007 9:07 AM > To: dba-sqlserver at databaseadvisors.com; 'Access Developers discussion and > problem solving' > Subject: Re: [AccessD] [dba-SQLServer] Bulk insert and table names > > Hi John > > List of SQL 2000 Keywords > > http://msdn2.microsoft.com/en-us/library/aa238507(SQL.80).aspx > > > Martin > > > Martin Reid > Telephone: 02890974465 > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Tue Oct 2 11:11:45 2007 From: jwcolby at colbyconsulting.com (jwcolby) Date: Tue, 2 Oct 2007 12:11:45 -0400 Subject: [dba-SQLServer] Suspect database Message-ID: <016d01c8050e$eeb24280$6c7aa8c0@M90> I lost power during a database operation and now that specific database shows "(suspect)". What does that mean? What is the standard procedure for restoring such a database? Is there a process for checking / repairing a "suspect" database? John W. Colby Colby Consulting www.ColbyConsulting.com From fhtapia at gmail.com Tue Oct 2 17:09:42 2007 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 2 Oct 2007 15:09:42 -0700 Subject: [dba-SQLServer] Suspect database In-Reply-To: <016d01c8050e$eeb24280$6c7aa8c0@M90> References: <016d01c8050e$eeb24280$6c7aa8c0@M90> Message-ID: http://www.sqlservercentral.com/articles/Administering/unmarksuspect/137/ Help! My Database is Marked Suspect. By Brian Knight, 2004/03/31 Total article views: 46830 | Views in the last 30 days: 1657 Rate this | Join the discussion | Briefcase | Print A database can be marked for many reasons. Generally it falls into the following conditions : - A database or log file is missing. - In SQL 6.5, a device may not be present or in 7.0/2000 a file may not exist. - SQL Server may not have been able to restore the database in ample time. - The database could be corrupt. - The database is being help by the operating system. This could be a 3rd party backup software or defrag software. I've had even a virus scanning software cause this once. - SQL Server does not have enough space to recover the database on startup. *To fix this problem, perform the following functions:* 1. Review the SQL Server and NT error logs to see if you can find where the problem occured. 2. Start SQL Server in single user mode. - Go to your control panel and services. - Stop SQL Server - Add the -m switch in the parameters pane below. - Start SQL Server 3. Run sp_resetstatus with the @dbname parameter. (ie : sp_resetstatus @dbname = "pubs") 4. Perform detailed DBCC checks (CHECKDB, CHECKALLOC, etc) 5. Run a few random queries to see if you experience any problems. 6. If no problems occur, stop and start SQL Server and open the database to production. As an absolute last resort, you can place your database in emergency mode. By placing it in this mode, you will be allowed to copy data out of the database, even if the data is corrupt. To place your database in emergency mode, use the following command: SP_CONFIGURE 'allow updates', 1 RECONFIGURE WITH OVERRIDE GO UPDATE master..sysdatabases set status = -32768 WHERE name = 'pubs' GO SP_CONFIGURE 'allow updates', 0 RECONFIGURE WITH OVERRIDE You can then BCP data out and place it into a different database. On 10/2/07, jwcolby wrote: > > I lost power during a database operation and now that specific database > shows "(suspect)". What does that mean? What is the standard procedure > for > restoring such a database? Is there a process for checking / repairing a > "suspect" database? > > John W. Colby > Colby Consulting > www.ColbyConsulting.com > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From jwcolby at colbyconsulting.com Fri Oct 5 11:52:54 2007 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 5 Oct 2007 12:52:54 -0400 Subject: [dba-SQLServer] Importing XML into a database Message-ID: <000901c80770$2cefbe20$657aa8c0@M90> I have found / written code in VB.Net to allow a class to write (and read) it's data out to a text file on disk. I use this ATM to log my import process. When I am done I have a log file per file imported. I will eventually be switching to a direct write to a data table but for now I need to know if I can import these log files into a table. The XML produced by the code looks like the following (actual file written): AK Complete 205453 \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt 2007-10-03T12:55:49.890375-04:00 2007-10-03T12:57:15.49325-04:00 0 205453 90071218 : 10/3/2007 12:55:49 PM : Read Directory: TaxRolls 90071234 : 10/3/2007 12:55:49 PM : Loading CSVReader10/3/2007 12:55:49 PM 90071234 : 10/3/2007 12:55:49 PM : Read File: \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt 90071250 : 10/3/2007 12:55:49 PM : File Loaded: \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt 90071296 : 10/3/2007 12:55:49 PM : Bulk Copy: tblTaxRolls 90116640 : 10/3/2007 12:56:35 PM : Bulk Copy Finished: tblTaxRolls 90116656 : 10/3/2007 12:56:35 PM : RECORDS READ: 205453 90116656 : 10/3/2007 12:56:35 PM : RECORDS BULK COPIED: 205453 10/3/2007 12:56:35 PM : Copy Temp table AK_X to the permanent table tblTaxRolls 10/3/2007 12:57:15 PM : Temp table copied AK_X to the permanent table tblTaxRolls 10/3/2007 12:57:15 PM : DROPPED Temp table AK_X 90156765 : 10/3/2007 12:57:15 PM : Move to Archive: \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\Archive\AK.txt Can SQL Server just read these files? Does anyone have any VB.Net code to read a file such as this and append the data to a table? John W. Colby Colby Consulting www.ColbyConsulting.com From pcs at azizaz.com Mon Oct 8 07:37:18 2007 From: pcs at azizaz.com (pcs at azizaz.com) Date: Mon, 8 Oct 2007 22:37:18 +1000 (EST) Subject: [dba-SQLServer] What datatype to use for a Time field Message-ID: <20071008223718.DEY24405@dommail.onthenet.com.au> Hi, What datatype to use when creating a field / column to handle handle time - say in 24 hour format - If I use DateTime datatype - when entering 10:00; 14:00 or 2:00 PM the system enters current date and the time - I just want the time part! In Access you could easily format the field to display the time element only. And if removing the Format element on the field - it still only displays the time element. What's 'best practice' is SQL? (using SQL2005) Another question: How to widen the last column in a view in SSMS ?? Regards Borge From fuller.artful at gmail.com Mon Oct 8 08:22:09 2007 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 8 Oct 2007 09:22:09 -0400 Subject: [dba-SQLServer] What datatype to use for a Time field In-Reply-To: <20071008223718.DEY24405@dommail.onthenet.com.au> References: <20071008223718.DEY24405@dommail.onthenet.com.au> Message-ID: <29f585dd0710080622ne7a962dt6a9f5ecaa29572cc@mail.gmail.com> 1. This is always a tough one conceptually, IME. I have wrestled with this one a dozen times at least. I have finally concluded that a moment in time implies a date and that either the database or the front end ought to supply said date. Noon on Monday is not the same as Noon on Tuesday, except in terms of presentation, and Noon on no date is a meaningless concept. This may seem an academic distinction to some readers, but I don't see any viable alternatives. Your FE may just request an abstract time, such as preferred lunch hour. In such a case I wouldn't use a datetime data type. In fact, I just had one of these crop up, and fortunately the requirement was "on the hour" -- so I created a lookup table called Hours and populated it with two columns and 24 records, the first column being autonumber (1...24, conveniently corresponding to military time), the second column being "1 PM" etc. Either you want a real representation of date/time or you want an abstract concept called Time. These two things are IMO quite different. Just my $.02 on this subject. 2. Drag the right edge of the column header out as far as you wish. hth, Arthur On 10/8/07, pcs at azizaz.com wrote: > > Hi, > > What datatype to use when creating a field / column to > handle handle time - say in 24 hour format - > If I use DateTime datatype - when entering 10:00; 14:00 or > 2:00 PM the system enters current date and the time - I just > want the time part! > > In Access you could easily format the field to display the > time element only. > And if removing the Format element on the field - it still > only displays the time element. > > What's 'best practice' is SQL? (using SQL2005) > > Another question: > How to widen the last column in a view in SSMS ?? > > Regards > Borge > _______________________________________________ > 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 Oct 8 08:27:19 2007 From: ssharkins at gmail.com (Susan Harkins) Date: Mon, 8 Oct 2007 09:27:19 -0400 Subject: [dba-SQLServer] What datatype to use for a Time field References: <20071008223718.DEY24405@dommail.onthenet.com.au> <29f585dd0710080622ne7a962dt6a9f5ecaa29572cc@mail.gmail.com> Message-ID: <001a01c809ae$f61d1640$4b3a8343@SusanOne> Nicely done Arthur. My next question would be -- will the date part ever be used as a date component? Susan H. > > Either you want a real representation of date/time or you want an abstract > concept called Time. These two things are IMO quite different. Just my > $.02 > on this subject. From fuller.artful at gmail.com Mon Oct 8 08:37:50 2007 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 8 Oct 2007 09:37:50 -0400 Subject: [dba-SQLServer] Canadian Thanksgiving Message-ID: <29f585dd0710080637m7beea296tbd5412cd413cad75@mail.gmail.com> It's CDN Thanksgiving, so here is my Thanksgiving: Thank you all for being here on these various dba-subgroups: I learn somethings every day here, which explains my reading virtually every message here. Thank you all! Basically I'm a vegetarian, not for any spiritual or dietary reasons, and I do allow myself to eat meat on various celebratory occasions, this being one of them. I surely feel the pain in the morning, however, but it's nice to share food and give thanks with friends. We have it sooooo good. We are not murdering each other. We may have slight disagreements, to be sure, but we get along and learn from one another. That is something precious for which to be thankful. I realize that the USA members have to wait another month or so celebrate, and that this celebratory day may mean little or nothing to members in other parts of the world, but anyway, Thanks to you all I am a better programmer than I was. Arthur From fuller.artful at gmail.com Mon Oct 8 09:06:05 2007 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 8 Oct 2007 10:06:05 -0400 Subject: [dba-SQLServer] What datatype to use for a Time field In-Reply-To: <001a01c809ae$f61d1640$4b3a8343@SusanOne> References: <20071008223718.DEY24405@dommail.onthenet.com.au> <29f585dd0710080622ne7a962dt6a9f5ecaa29572cc@mail.gmail.com> <001a01c809ae$f61d1640$4b3a8343@SusanOne> Message-ID: <29f585dd0710080706s1efa308fj52d0dc237a8640bd@mail.gmail.com> Thanks, Susan! Case 1: You have two different columns, date and time (this case makes no sense to me, but I've seen it so I present it). The FE|BE distinction becomes important here. If you want to record Date+Time, then do it in the BE in one column; the FE is another story. You might want to present the date and time as distinct FE objects, and that's cool, but in the BE record it as one column. Case 2: You have a column called PreferredTimeToEndureYetAnotherPhilosophyLecture. Don't record it as a date/time data type. Model it instead as a number (perhaps using the proposed model that uses a table called Hours), in which case you're recording an integer not a date/time object with a meaningless date. Case 3: I am interested in listing all the Horse Riders who have booked their lesson time as 2pm, regardless of date. This is identical to Case 2, with just a tad different phrasing. What has worked for me is the lookup table Hours, with precisely 24 rows. That assumes "on the hour" degrees, and if you have to grain it more precisely then add more rows, for example 13.00, 13.15, 13.30, 13.45. Either way, this model makes it quite simple to isolate (query) the people who want their tennis lesson at 13.45 (1:45pm). The FE can handle the overhead quite easily, and the BE can too. A. On 10/8/07, Susan Harkins wrote: > > Nicely done Arthur. > > My next question would be -- will the date part ever be used as a date > component? > > Susan H. > > From spike at tenbus.co.uk Mon Oct 8 14:47:15 2007 From: spike at tenbus.co.uk (Webadmin - Tenbus) Date: Mon, 08 Oct 2007 20:47:15 +0100 Subject: [dba-SQLServer] What datatype to use for a Time field In-Reply-To: <001a01c809ae$f61d1640$4b3a8343@SusanOne> References: <20071008223718.DEY24405@dommail.onthenet.com.au> <29f585dd0710080622ne7a962dt6a9f5ecaa29572cc@mail.gmail.com> <001a01c809ae$f61d1640$4b3a8343@SusanOne> Message-ID: <470A8943.309@tenbus.co.uk> Susan Harkins wrote: > Nicely done Arthur. > > My next question would be -- will the date part ever be used as a date > component? > > Susan H. > > > >> Either you want a real representation of date/time or you want an abstract >> concept called Time. These two things are IMO quite different. Just my >> $.02 >> on this subject. >> > > I agree with Arthur here. I allways use a date time field even if only the time part needs to be displayed. The other "true" time only variable would be an elapsed time or the difference between two date/times. I've seem to many arguments (elsewhere) about the semantic meaning of things to argue ;-) Regards! Chris Foote From accessd at shaw.ca Mon Oct 8 14:55:49 2007 From: accessd at shaw.ca (Jim Lawrence) Date: Mon, 08 Oct 2007 12:55:49 -0700 Subject: [dba-SQLServer] Canadian Thanksgiving In-Reply-To: <29f585dd0710080637m7beea296tbd5412cd413cad75@mail.gmail.com> Message-ID: Have a great day Arthur... Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Monday, October 08, 2007 6:38 AM To: Access Developers discussion and problem solving; Discussion of Hardware and Software issues; dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Canadian Thanksgiving It's CDN Thanksgiving, so here is my Thanksgiving: Thank you all for being here on these various dba-subgroups: I learn somethings every day here, which explains my reading virtually every message here. Thank you all! Basically I'm a vegetarian, not for any spiritual or dietary reasons, and I do allow myself to eat meat on various celebratory occasions, this being one of them. I surely feel the pain in the morning, however, but it's nice to share food and give thanks with friends. We have it sooooo good. We are not murdering each other. We may have slight disagreements, to be sure, but we get along and learn from one another. That is something precious for which to be thankful. I realize that the USA members have to wait another month or so celebrate, and that this celebratory day may mean little or nothing to members in other parts of the world, but anyway, Thanks to you all I am a better programmer than I was. Arthur _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pcs at azizaz.com Mon Oct 8 23:48:48 2007 From: pcs at azizaz.com (pcs at azizaz.com) Date: Tue, 9 Oct 2007 14:48:48 +1000 (EST) Subject: [dba-SQLServer] What datatype to use for a Time field Message-ID: <20071009144848.DEZ86189@dommail.onthenet.com.au> Hi Arthur, Thanks for your comment. In the meantime I read and learned a bit more from the Help Section of SQL2005. a) If you use a character field to express a time element for example 9:43; 15:15; 3:15PM SQL will implicit cast it into a DateTime datatype with the date part of 1 Jan 1900 added to it when used in functions etc. b) If you use a DateTime field to store only the Hour:Min value that you are interested in, SQL will add current date into the field plus the Time component when adding it directly in the table using SSMS. Unless you take steps in your FE to ensure that all Hour:Min values entered has the same DateComponent entered you are in trouble if you start using the values in various calculations You can of course extract just the timepart, and cast the timepart as DateTime datatype again to ensure that all your Hour:Min values are on the same Day footing so to speak... But in your SQL table you will have a funny representation of your Hour:Min values - i.e. various Dates in the DatePart I came up with a solution that uses a Character Field for the Start and End Times for the Shifts. Value entered via Combobox with preset values like: 0:00 0:15 0:30 .... 23:30 23:45 23:59 If you are interested, this is my situation: I have a pool of casual employees (Relief Staff Candidates) who have indicated - within a 24 hour period - their - Default Shift Availability (StartTime - EndTime) - Exception Shift Availablity with StartDate and EndDate indicating the period that the Exception Shift Availability is in force... I have a number of Requested Relief Positions each one for a particular shift. For each one I need to match up a Relief Staff Candidate .... So for example a Requested Position can be from 10 October to 15 October 2008 Shift from 9:00 to 15:00. I need to filter on all casual employees that have said: I am by default available between X and Y except for the period between This Date and That Date where I am available between W and Z So first I have to figure out which Shift Availablity for each Casual record to use .... Then once I've determined that, I need to check if the Requested Shift falls within the Shift Availability and if so include the Casual Record in the Filter. With the help of two scalar valued functions that helps me determine whether to use the Default OR the Exception Shift availability (is there any 'overlap' between the Requested Period and the Exception Shift Period - then use Exeception Shift Period) and whether the Requested Shift falls within the Persons's shift availability I can now - using one Stored Procedure - filter out the relevant Relief Staff Candidates. The Shift is only one part of the overall filtering to match up a Relief Staff Candidate... Regards borge ---- Original message ---- >Date: Mon, 8 Oct 2007 09:22:09 -0400 >From: "Arthur Fuller" >Subject: Re: [dba-SQLServer] What datatype to use for a Time field >To: dba-sqlserver at databaseadvisors.com > >1. This is always a tough one conceptually, IME. I have wrestled with this >one a dozen times at least. I have finally concluded that a moment in time >implies a date and that either the database or the front end ought to supply >said date. Noon on Monday is not the same as Noon on Tuesday, except in >terms of presentation, and Noon on no date is a meaningless concept. > >This may seem an academic distinction to some readers, but I don't see any >viable alternatives. Your FE may just request an abstract time, such as >preferred lunch hour. In such a case I wouldn't use a datetime data type. In >fact, I just had one of these crop up, and fortunately the requirement was >"on the hour" -- so I created a lookup table called Hours and populated it >with two columns and 24 records, the first column being autonumber (1...24, >conveniently corresponding to military time), the second column being "1 PM" >etc. > >Either you want a real representation of date/time or you want an abstract >concept called Time. These two things are IMO quite different. Just my $.02 >on this subject. > >2. Drag the right edge of the column header out as far as you wish. > >hth, >Arthur > >On 10/8/07, pcs at azizaz.com wrote: >> >> Hi, >> >> What datatype to use when creating a field / column to >> handle handle time - say in 24 hour format - >> If I use DateTime datatype - when entering 10:00; 14:00 or >> 2:00 PM the system enters current date and the time - I just >> want the time part! >> >> In Access you could easily format the field to display the >> time element only. >> And if removing the Format element on the field - it still >> only displays the time element. >> >> What's 'best practice' is SQL? (using SQL2005) >> >> Another question: >> How to widen the last column in a view in SSMS ?? >> >> Regards >> Borge >> _______________________________________________ >> 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 pcs at azizaz.com Wed Oct 10 22:41:21 2007 From: pcs at azizaz.com (pcs at azizaz.com) Date: Thu, 11 Oct 2007 13:41:21 +1000 (EST) Subject: [dba-SQLServer] Control of SortOrder? Message-ID: <20071011134121.DFD82621@dommail.onthenet.com.au> Hello, SQL2005 Based on the value of an input parameter I want to control the SortOrder on a particular column. Can it be done, and if so how? I've been trying with CASE statements .. no luck, I'm stuck! I've tried ORDER BY T2.HighestQualificationEnum (CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE DESC END), T3.Ranking, @p2_intNumberOfDays- CASE WHEN datediff(d, CONVERT(DATETIME, @p1_ReqStartDate , 102),T1.StartDate)>=@p2_intNumberOfDays THEN @p2_intNumberOfDays ELSE datediff(d, CONVERT(DATETIME, @p1_ReqStartDate , 102),T1.StartDate) END (The last sortorder item that also includes a CASE statement works!) regards borge From michael at ddisolutions.com.au Thu Oct 11 03:25:23 2007 From: michael at ddisolutions.com.au (Michael Maddison) Date: Thu, 11 Oct 2007 18:25:23 +1000 Subject: [dba-SQLServer] Control of SortOrder? References: <20071011134121.DFD82621@dommail.onthenet.com.au> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D01289EAC@ddi-01.DDI.local> Borge, I believe you must Order By a field. BTW I'm testing in SQL2K So, T3.Ranking, is fine I don't believe you can change ASC to DESC this way. '(CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE DESC END)' It wont compile for me because of the reserved words ASC & DESC The last one is interesting, but is it doing what you think it is? The case statement seems to return a #, I assumed it will then sort by the column ordinal returned??? I couldn't actually get it to work though, it would compile but had no effect on sort order. When I have complicated sort orders I would create a computed column to then sort on. Append your 3 columns together in a way that makes sense and sort on that? cheers Michael M Hello, SQL2005 Based on the value of an input parameter I want to control the SortOrder on a particular column. Can it be done, and if so how? I've been trying with CASE statements .. no luck, I'm stuck! I've tried ORDER BY T2.HighestQualificationEnum (CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE DESC END), T3.Ranking, @p2_intNumberOfDays- CASE WHEN datediff(d, CONVERT(DATETIME, @p1_ReqStartDate , 102),T1.StartDate)>=@p2_intNumberOfDays THEN @p2_intNumberOfDays ELSE datediff(d, CONVERT(DATETIME, @p1_ReqStartDate , 102),T1.StartDate) END (The last sortorder item that also includes a CASE statement works!) regards borge _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pcs at azizaz.com Thu Oct 11 07:12:00 2007 From: pcs at azizaz.com (pcs at azizaz.com) Date: Thu, 11 Oct 2007 22:12:00 +1000 (EST) Subject: [dba-SQLServer] Control of SortOrder? Message-ID: <20071011221200.DFE35165@dommail.onthenet.com.au> Michael, Since the column to sort on is Integer I was suggested to use this workaround... which works: ORDER BY CASE WHEN @p7_ReqPosID = 0 THEN T2.HighestQualificationEnum * -1 ELSE T2.HighestQualificationEnum END DESC, ..notice placement of the DESC But what to do if the column was a char field? The last CASE statement below has been tested to work ok too.. Regards Borge ---- Original message ---- >Date: Thu, 11 Oct 2007 18:25:23 +1000 >From: "Michael Maddison" >Subject: Re: [dba-SQLServer] Control of SortOrder? >To: > >Borge, > >I believe you must Order By a field. BTW I'm testing in SQL2K > >So, >T3.Ranking, is fine > >I don't believe you can change ASC to DESC this way. >'(CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE DESC END)' >It wont compile for me because of the reserved words ASC & DESC > >The last one is interesting, but is it doing what you think it is? >The case statement seems to return a #, I assumed it will then sort by >the column ordinal returned??? >I couldn't actually get it to work though, it would compile but had no >effect on sort order. > >When I have complicated sort orders I would create a computed column to >then sort on. >Append your 3 columns together in a way that makes sense and sort on >that? > >cheers > > >Michael M > >Hello, > >SQL2005 > >Based on the value of an input parameter I want to control the SortOrder >on a particular column. > >Can it be done, and if so how? > >I've been trying with CASE statements .. no luck, I'm stuck! > >I've tried > >ORDER BY >T2.HighestQualificationEnum (CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE >DESC END), T3.Ranking, >@p2_intNumberOfDays- > CASE > WHEN datediff(d, CONVERT(DATETIME, >@p1_ReqStartDate , 102),T1.StartDate)>=@p2_intNumberOfDays > THEN @p2_intNumberOfDays > ELSE datediff(d, CONVERT(DATETIME, >@p1_ReqStartDate , 102),T1.StartDate) > END > >(The last sortorder item that also includes a CASE statement >works!) > >regards >borge >_______________________________________________ >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 michael at ddisolutions.com.au Thu Oct 11 19:17:09 2007 From: michael at ddisolutions.com.au (Michael Maddison) Date: Fri, 12 Oct 2007 10:17:09 +1000 Subject: [dba-SQLServer] Control of SortOrder? References: <20071011221200.DFE35165@dommail.onthenet.com.au> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D01289EAD@ddi-01.DDI.local> What a shifty little hack that is ;-))) To do the same with chars I guess you would need to convert them to ints... a = 1 b = 2 Don't think there is a builtin function for this but I assume its what SQL does in the background anyway. I still don't understand how the 3rd part can actually work? To me it evaluates to (5-3) which seems to do nothing, at all... cheers Michael M -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of pcs at azizaz.com Sent: Thursday, 11 October 2007 10:12 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Control of SortOrder? Michael, Since the column to sort on is Integer I was suggested to use this workaround... which works: ORDER BY CASE WHEN @p7_ReqPosID = 0 THEN T2.HighestQualificationEnum * -1 ELSE T2.HighestQualificationEnum END DESC, ..notice placement of the DESC But what to do if the column was a char field? The last CASE statement below has been tested to work ok too.. Regards Borge ---- Original message ---- >Date: Thu, 11 Oct 2007 18:25:23 +1000 >From: "Michael Maddison" >Subject: Re: [dba-SQLServer] Control of SortOrder? >To: > >Borge, > >I believe you must Order By a field. BTW I'm testing in SQL2K > >So, >T3.Ranking, is fine > >I don't believe you can change ASC to DESC this way. >'(CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE DESC END)' >It wont compile for me because of the reserved words ASC & DESC > >The last one is interesting, but is it doing what you think it is? >The case statement seems to return a #, I assumed it will then sort by >the column ordinal returned??? >I couldn't actually get it to work though, it would compile but had no >effect on sort order. > >When I have complicated sort orders I would create a computed column to >then sort on. >Append your 3 columns together in a way that makes sense and sort on >that? > >cheers > > >Michael M > >Hello, > >SQL2005 > >Based on the value of an input parameter I want to control the SortOrder >on a particular column. > >Can it be done, and if so how? > >I've been trying with CASE statements .. no luck, I'm stuck! > >I've tried > >ORDER BY >T2.HighestQualificationEnum (CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE >DESC END), T3.Ranking, >@p2_intNumberOfDays- > CASE > WHEN datediff(d, CONVERT(DATETIME, >@p1_ReqStartDate , 102),T1.StartDate)>=@p2_intNumberOfDays > THEN @p2_intNumberOfDays > ELSE datediff(d, CONVERT(DATETIME, >@p1_ReqStartDate , 102),T1.StartDate) > END > >(The last sortorder item that also includes a CASE statement >works!) > >regards >borge >_______________________________________________ >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 pcs at azizaz.com Thu Oct 11 21:24:50 2007 From: pcs at azizaz.com (pcs at azizaz.com) Date: Fri, 12 Oct 2007 12:24:50 +1000 (EST) Subject: [dba-SQLServer] Control of SortOrder? Message-ID: <20071012122450.DFF78063@dommail.onthenet.com.au> Michael, Yes, when I was suggested the trick I thought the same... won't try it on a char field though.... To fill you in with regards to You wrote: >I still don't understand how the 3rd part can actually work? >To me it evaluates to (5-3) which seems to do nothing, at all... @p2_intNumberOfDays- CASE WHEN datediff(d, CONVERT(DATETIME, @p1_ReqStartDate , 102),T1.StartDate)>=@p2_intNumberOfDays THEN @p2_intNumberOfDays ELSE datediff(d, CONVERT(DATETIME, @p1_ReqStartDate , 102),T1.StartDate) @p1_ReqStartDate is the Start Date of the requested relief position @p2_intNumberOfDays is the duration period of the requested relief position T1.StartDate is the start date of the first relief assignment / unavailability period of a Relief Staff Candidate that this Relief Staff Candidate is already committed to ... a subquery has already filtered out those Relief Staff Candidates for which there is a 'collision' with the Start Date of the Requested Period .... So the resulting integer (2) indicates in this context is the number of days a Person cannot serve in the Requested Period - so 0 means I can serve the full period, 1 I can serve the full period except the last day etc... In the subset of queried Candidate records the sort order then is by who can serve the most days of the requested period all other search parameters being equal .... and the aim of the whole query excercise is to identify the top one and offer this person the Requested Relief Positon ... the rule being if we can't get a person the whole period let's at least get a person part of the period and keep looking who can fill the remaining period .... Regards borge ---- Original message ---- >Date: Fri, 12 Oct 2007 10:17:09 +1000 >From: "Michael Maddison" >Subject: Re: [dba-SQLServer] Control of SortOrder? >To: > >What a shifty little hack that is ;-))) > >To do the same with chars I guess you would need to convert them to >ints... >a = 1 >b = 2 > >Don't think there is a builtin function for this but I assume its what >SQL does in the background anyway. > >I still don't understand how the 3rd part can actually work? >To me it evaluates to (5-3) which seems to do nothing, at all... > >cheers > >Michael M > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of >pcs at azizaz.com >Sent: Thursday, 11 October 2007 10:12 PM >To: dba-sqlserver at databaseadvisors.com >Subject: Re: [dba-SQLServer] Control of SortOrder? > >Michael, > >Since the column to sort on is Integer I was suggested to use this >workaround... which works: > >ORDER BY > CASE > WHEN @p7_ReqPosID = 0 > THEN T2.HighestQualificationEnum * -1 > ELSE T2.HighestQualificationEnum > END DESC, > >..notice placement of the DESC > >But what to do if the column was a char field? > >The last CASE statement below has been tested to work ok too.. > >Regards >Borge > >---- Original message ---- >>Date: Thu, 11 Oct 2007 18:25:23 +1000 >>From: "Michael Maddison" >>Subject: Re: [dba-SQLServer] Control of SortOrder? >>To: >> >>Borge, >> >>I believe you must Order By a field. BTW I'm testing in >SQL2K >> >>So, >>T3.Ranking, is fine >> >>I don't believe you can change ASC to DESC this way. >>'(CASE WHEN @p7_ReqPosID = 0 THEN ASC ELSE DESC END)' >>It wont compile for me because of the reserved words ASC & >DESC >> >>The last one is interesting, but is it doing what you think >it is? >>The case statement seems to return a #, I assumed it will >then sort by >>the column ordinal returned??? >>I couldn't actually get it to work though, it would compile >but had no >>effect on sort order. >> >>When I have complicated sort orders I would create a >computed column to >>then sort on. >>Append your 3 columns together in a way that makes sense >and sort on >>that? >> >>cheers >> >> >>Michael M >> >>Hello, >> >>SQL2005 >> >>Based on the value of an input parameter I want to control >the SortOrder >>on a particular column. >> >>Can it be done, and if so how? >> >>I've been trying with CASE statements .. no luck, I'm stuck! >> >>I've tried >> >>ORDER BY >>T2.HighestQualificationEnum (CASE WHEN @p7_ReqPosID = 0 >THEN ASC ELSE >>DESC END), T3.Ranking, >>@p2_intNumberOfDays- >> CASE >> WHEN datediff(d, CONVERT(DATETIME, >>@p1_ReqStartDate , 102),T1.StartDate)>=@p2_intNumberOfDays >> THEN @p2_intNumberOfDays >> ELSE datediff(d, CONVERT(DATETIME, >>@p1_ReqStartDate , 102),T1.StartDate) >> END >> >>(The last sortorder item that also includes a CASE statement >>works!) >> >>regards >>borge >>_______________________________________________ >>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 darren at activebilling.com.au Fri Oct 12 01:08:53 2007 From: darren at activebilling.com.au (Darren D) Date: Fri, 12 Oct 2007 16:08:53 +1000 Subject: [dba-SQLServer] ADProject: Getting Database Name Message-ID: <200710120608.l9C68jrm006304@databaseadvisors.com> Hi All Cross posted to AccessD and dba_SQL Server I want to get the Server name (Data Source) from code - I can get the dB name Now I want just the server name as well - Not all the other stuff that comes with the .Connection property Can anyone assist? Many thanks in advance Darren From ebarro at verizon.net Wed Oct 17 14:03:43 2007 From: ebarro at verizon.net (Eric Barro) Date: Wed, 17 Oct 2007 12:03:43 -0700 Subject: [dba-SQLServer] Importing XML into a database In-Reply-To: <000901c80770$2cefbe20$657aa8c0@M90> Message-ID: <0JQ200332KYDJV90@vms044.mailsrvcs.net> John, I'll have to dig into my code library but generally you convert the XML to a dataset and then you can write the dataset to a SQL table. Eric -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Friday, October 05, 2007 9:53 AM To: 'Access Developers discussion and problem solving'; dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] Importing XML into a database I have found / written code in VB.Net to allow a class to write (and read) it's data out to a text file on disk. I use this ATM to log my import process. When I am done I have a log file per file imported. I will eventually be switching to a direct write to a data table but for now I need to know if I can import these log files into a table. The XML produced by the code looks like the following (actual file written): AK Complete 205453 \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt 2007-10-03T12:55:49.890375-04:00 2007-10-03T12:57:15.49325-04:00 0 205453 90071218 : 10/3/2007 12:55:49 PM : Read Directory: TaxRolls 90071234 : 10/3/2007 12:55:49 PM : Loading CSVReader10/3/2007 12:55:49 PM 90071234 : 10/3/2007 12:55:49 PM : Read File: \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt 90071250 : 10/3/2007 12:55:49 PM : File Loaded: \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt 90071296 : 10/3/2007 12:55:49 PM : Bulk Copy: tblTaxRolls 90116640 : 10/3/2007 12:56:35 PM : Bulk Copy Finished: tblTaxRolls 90116656 : 10/3/2007 12:56:35 PM : RECORDS READ: 205453 90116656 : 10/3/2007 12:56:35 PM : RECORDS BULK COPIED: 205453 10/3/2007 12:56:35 PM : Copy Temp table AK_X to the permanent table tblTaxRolls 10/3/2007 12:57:15 PM : Temp table copied AK_X to the permanent table tblTaxRolls 10/3/2007 12:57:15 PM : DROPPED Temp table AK_X 90156765 : 10/3/2007 12:57:15 PM : Move to Archive: \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\Archive\AK.txt Can SQL Server just read these files? Does anyone have any VB.Net code to read a file such as this and append the data to a table? John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From pcs at azizaz.com Wed Oct 17 23:11:08 2007 From: pcs at azizaz.com (pcs at azizaz.com) Date: Thu, 18 Oct 2007 14:11:08 +1000 (EST) Subject: [dba-SQLServer] Importing XML into a database Message-ID: <20071018141108.DFP71360@dommail.onthenet.com.au> John, I don't know if this would be of any help to you. The Transact-SQL keyword named OPENXML along with two supporting system stored procedures: sp_xml_preparedocument and sp_xml_removedocument may be what you need to do the job. Here is a pointer to an article: http://www.perfectxml.com/articles/xml/openxml.asp Using some of the article samples and slightly modifying your xml file I created this SP below. Try and run it.. You can replace the Select with an Insert etc... If you know how to reference the xml file instead of having the text hardcoded let me know .... Regards borge **************** DECLARE @idoc int DECLARE @doc varchar (1000) SET @doc =' AK Complete 205453 \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.tx t 2007-10-03T12:55:49.890375-04:00 2007-10-03T12:57:15.49325-04:00 0 205453 90071218 : 10/3/2007 12:55:49 PM : Read Directory: TaxRolls 90071234 : ' --Create an internal representation of the XML document EXEC sp_xml_preparedocument @idoc OUTPUT, @doc -- Execute a SELECT statement that uses the OPENXML rowset provider SELECT * FROM OPENXML (@idoc, '/clsLogData/pTblName',3) WITH ( pStatus varchar(80), pCommittedID int, pFileSpec varchar(255), pStartTime varchar(255), pStopTime varchar(255), pStartID int, pStopID int, pMemo varchar(max) ) -- Clear the XML document from memory EXEC sp_xml_removedocument @idoc ********************* ---- Original message ---- >Date: Wed, 17 Oct 2007 12:03:43 -0700 >From: "Eric Barro" >Subject: Re: [dba-SQLServer] Importing XML into a database >To: > >John, > >I'll have to dig into my code library but generally you convert the XML to a >dataset and then you can write the dataset to a SQL table. > >Eric > >-----Original Message----- >From: dba-sqlserver-bounces at databaseadvisors.com >[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby >Sent: Friday, October 05, 2007 9:53 AM >To: 'Access Developers discussion and problem solving'; >dba-sqlserver at databaseadvisors.com >Subject: [dba-SQLServer] Importing XML into a database > >I have found / written code in VB.Net to allow a class to write (and read) >it's data out to a text file on disk. I use this ATM to log my import >process. When I am done I have a log file per file imported. I will >eventually be switching to a direct write to a data table but for now I need >to know if I can import these log files into a table. The XML produced by >the code looks like the following (actual file written): > > >xmlns:xsd="http://www.w3.org/2001/XMLSchema"> > AK > Complete > 205453 > \\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.tx t > 2007-10-03T12:55:49.890375-04:00 > 2007-10-03T12:57:15.49325-04:00 > 0 > 205453 > 90071218 : 10/3/2007 12:55:49 PM : Read Directory: TaxRolls >90071234 : 10/3/2007 12:55:49 PM : Loading CSVReader10/3/2007 12:55:49 PM >90071234 : 10/3/2007 12:55:49 PM : Read File: >\\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt >90071250 : 10/3/2007 12:55:49 PM : File Loaded: >\\Stonehenge\psm\Data\FirstAmerican\TaxRolls\AK.txt >90071296 : 10/3/2007 12:55:49 PM : Bulk Copy: tblTaxRolls 90116640 : >10/3/2007 12:56:35 PM : Bulk Copy Finished: tblTaxRolls >90116656 : 10/3/2007 12:56:35 PM : RECORDS READ: 205453 >90116656 : 10/3/2007 12:56:35 PM : RECORDS BULK COPIED: 205453 >10/3/2007 12:56:35 PM : Copy Temp table AK_X to the permanent table >tblTaxRolls >10/3/2007 12:57:15 PM : Temp table copied AK_X to the permanent table >tblTaxRolls >10/3/2007 12:57:15 PM : DROPPED Temp table AK_X >90156765 : 10/3/2007 12:57:15 PM : Move to Archive: >\\Stonehenge\psm\Data\FirstAmerican\TaxRolls\Archive\AK.txt< /pMemo> > > >Can SQL Server just read these files? Does anyone have any VB.Net code to >read a file such as this and append the data to a table? > >John W. Colby >Colby Consulting >www.ColbyConsulting.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 Mon Oct 29 21:02:48 2007 From: fuller.artful at gmail.com (Arthur Fuller) Date: Mon, 29 Oct 2007 22:02:48 -0400 Subject: [dba-SQLServer] DB2 anyone? Message-ID: <29f585dd0710291902p5dec9258i13b2504753f72d15@mail.gmail.com> Anybody on this list familiar with DB2? I installed DB2 Express. I want to import a database from a bunch of text files. There are some files that purport to help me do this, with weird extensions like .zpl or something. I also have the database installed in SQL Server, Oracle and MySQL, so perhaps I could import it from there. I looked at one DB2 utility but it seemed to want comma-delimited files and the text files I have are fixed-width. TIA, Arthur From michael at ddisolutions.com.au Tue Oct 30 00:26:20 2007 From: michael at ddisolutions.com.au (Michael Maddison) Date: Tue, 30 Oct 2007 16:26:20 +1100 Subject: [dba-SQLServer] DB2 anyone? References: <29f585dd0710291902p5dec9258i13b2504753f72d15@mail.gmail.com> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D01289FB6@ddi-01.DDI.local> Arthur, Never played with DB2 but can't DTS do the job? ODBC connection perhaps? regards Michael M Subject: [dba-SQLServer] DB2 anyone? Anybody on this list familiar with DB2? I installed DB2 Express. I want to import a database from a bunch of text files. There are some files that purport to help me do this, with weird extensions like .zpl or something. I also have the database installed in SQL Server, Oracle and MySQL, so perhaps I could import it from there. I looked at one DB2 utility but it seemed to want comma-delimited files and the text files I have are fixed-width. TIA, Arthur _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From accessd at shaw.ca Wed Oct 31 14:53:28 2007 From: accessd at shaw.ca (Jim Lawrence) Date: Wed, 31 Oct 2007 12:53:28 -0700 Subject: [dba-SQLServer] DB2 anyone? In-Reply-To: <29f585dd0710291902p5dec9258i13b2504753f72d15@mail.gmail.com> Message-ID: <8F9753E667814252BF0ACD3107A2D8B5@creativesystemdesigns.com> Hi Arthur: I finally got a reply from a friend who was trained in DB2. Her best suggestion was to import the data into another SQL DB like MS SQL and then export in a fashion the DB2 could import. Her other suggestion was to import the data into MS SQL and link the 2 databases and build the tables from there. Sorry to not be more helpful but DB2 seems to regards other DBs like MS regards Linux. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Monday, October 29, 2007 7:03 PM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] DB2 anyone? Anybody on this list familiar with DB2? I installed DB2 Express. I want to import a database from a bunch of text files. There are some files that purport to help me do this, with weird extensions like .zpl or something. I also have the database installed in SQL Server, Oracle and MySQL, so perhaps I could import it from there. I looked at one DB2 utility but it seemed to want comma-delimited files and the text files I have are fixed-width. TIA, Arthur _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com