sql-server-2000

T-SQL script - logic issues with timeline

柔情痞子 提交于 2019-12-04 08:30:19
Two temp tables are created and then loaded...Here's the schema. Create table #SH ([date] datetime, sched_id int, agent_id int) Create table #SD (sched_id int, start_minute int, length int, exception_code int) (Schema and design is something I can't change unfortunately, both temp tables are loaded from flat files. I can introduce and load new temp tables if needed). A little background - The #SH header table holds a persons schedule as 'Start_minute' and goes for 'schedule_length' in minutes. For example, if start minute and schedule length were both 480, that would read as 8am (8am = 480th

Try Catch in SQL Server 2000?

拥有回忆 提交于 2019-12-04 07:39:14
Is it possible using Try-Catch in SQL Server 2000 ? No, it is not possible. This was only from Sql Server 2005 Check TRY...CATCH (Transact-SQL) and check the Other Versions decyclone No. Try Catch block was introduced in SQL SERVER 2005 . Following article shows how you can use @@ERROR to check for errors. Understanding error handling in SQL Server 2000 Binil Instead you can user @@Error .. check this article about error handling thevan @@ERROR is a variable updated by the SQL Server database engine after each statement is executed on the server. We can see by Print @@Error No Try Catch Was

Rows in columns

浪尽此生 提交于 2019-12-04 07:19:53
问题 I have this table: Id Kind 1 MODEL 1 MOTOR 2 MODEL 2 MOTOR 3 MOTOR 4 MODEL And I want to insert into anothe table: IdModel IdMotor 1 1 1 2 1 3 2 1 2 2 2 3 4 1 4 2 4 3 I know how to do it with cursors, but it's indeed very slow. I've tried with union but it looks like today is not my best day! I also know this can be done in SQL 2005 with pivot, but I have to do it with SQL Server 2000. Any Transact-SQL guru out there with a good and quick query? Thanks in advance! 回答1: Looks like this will

SQL Server 2000: how to save an Image variable to a file in the file system from a stored procedure

安稳与你 提交于 2019-12-04 06:10:05
问题 I have a stored procedure that receives a @Data image parameter. And I want to save it to the file system from a stored procedure. Any idea how to do it? 回答1: You can use OLE automation (ADODB.Stream) to write binary data from a SQL Server 2000 stored procedure, as described here and here. The sample below uses a varbinary variable, but it should work similarly with your image parameter. DECLARE @Path VarChar(255) DECLARE @Data VarBinary(1000) SET @Data = 0x12345678 SET @Path = 'c:\test.dat'

SQL joining multiple tables

我的梦境 提交于 2019-12-04 03:50:06
问题 Using Microsoft SQL 2000, I will like to join multiples tables (A, B, C, and D) together. I know table A always exists. However, I only know at least one of the table form (B, C, D) exists. Is there any way I could do something like this to accomplish what I am trying to do? Select * form table a If table b exists left Join table b on a.id = b.id If table c exists left Join table c on a.id = c.id If table d exists left Join table d on a.id = d.id 回答1: You'll have to check the data dictionary

SQL to determine multiple date ranges (SQL Server 2000)

好久不见. 提交于 2019-12-04 01:58:25
问题 I have a table which contains an ID and a Date for an event. Each row is for one date. I am trying to determine consecutive date ranges and consolidate output to show the ID,StartDate,EndDate ID Date 200236 2011-01-02 00:00:00.000 200236 2011-01-03 00:00:00.000 200236 2011-01-05 00:00:00.000 200236 2011-01-06 00:00:00.000 200236 2011-01-07 00:00:00.000 200236 2011-01-08 00:00:00.000 200236 2011-01-09 00:00:00.000 200236 2011-01-10 00:00:00.000 200236 2011-01-11 00:00:00.000 200236 2011-01-12

INSTEAD OF UPDATE Trigger - is this possible?

让人想犯罪 __ 提交于 2019-12-03 23:53:12
问题 I am making some tweaks to a legacy application built on SQL Server 2000, needless to say I only want to do the absolute minimum in the fear that it may just all fall apart. I have a large table of users, tbUsers, with a BIT flag for IsDeleted. I want to archive off all current and future IsDeleted = 1 user records into my archive table tbDeletedUsers. Moving the currently deleted users is straight forward, however I want a way to move any future users where the IsDeleted flag is set. I could

SQL Server 2000 - ALTER TABLE + INSERT INTO = Errors?

醉酒当歌 提交于 2019-12-03 23:43:18
问题 I'm trying to alter a table to add a new column, then insert a new row into it. ALTER TABLE Roles ADD ModifiedDate DateTime; INSERT INTO Roles (Name, [Description], CreatedBy, BuiltIn, Created, ModifiedDate) VALUES ('Name', 'Description', 0, 1, GETDATE(), GETDATE()) but I get: Msg 207, Level 16, State 1, Line 1 Invalid column name 'ModifiedDate'. when i try to run the above SQL in SQL Server Management Studio. I think this is a Studio error, not a server error. If the SQL was run, it should

Schema, Owner for objects in MS SQL

半腔热情 提交于 2019-12-03 23:27:18
问题 By default, objects (tables, stored procedures, etc) are set up with the dbo owner/schema (I think ms sql 2000 calls it owner, while ms sql 2005 calls it schema) The owner/schema is really a role or user in the database. I've always left the default of dbo, but I've recently seen some examples in microsoft training books where some of their tables & stored procedures had different owners/schemas. When is it beneficial to do this and why? 回答1: The use of schemas is exceptionally beneficial

Passing delimited string to stored procedure to search database

限于喜欢 提交于 2019-12-03 22:21:29
问题 How can i pass a string delimited by space or comma to stored procedure and filter result? I'm trying to do something like - Parameter Value -------------------------- @keywords key1 key2 key3 Then is stored procedure i want to first find all records with first or last name like key1 filter step 1 with first or last name like key2 filter step 2 with first or last name like key 3 Another example: col1 | col2 | col3 ------------------------------------------------------------------------ hello