sql-server-2000

SQL query takes longer time when date range is smaller?

主宰稳场 提交于 2019-12-06 05:03:07
问题 I have a simple select statement which selects data from a SQL Server 2000 (so old) table with about 10-20 million rows like this - @startDate = '2014-01-25' -- yyyy-mm-dd @endDate = '2014-02-20' SELECT Id, 6-7 other columns FROM Table1 as t1 LEFT OUTER JOIN Table2 as t2 ON t1.Code = t2.Code WHERE t1.Id = 'G59' -- yes, its a varchar AND (t1.Entry_Date >= @startDate AND t1.Entry_Date < @endDate) This gives me about 40 K rows in about 10 seconds. But, if I set @startDate = '2014-01-30', keeping

Get list of tables but not include system tables (SQL Server 2K)?

假装没事ソ 提交于 2019-12-06 03:17:38
问题 I know I can get a list of tables from a given database with the following query: select * from information_schema.tables How do I go about excluding system tables though? 回答1: select name from sysobjects where type='U' 回答2: I know this is quite an old question, but someone's just edited it to resurrect it, and the "right" answer from my perspective isn't either of the two listed. The accepted answer includes some "system" tables ( dtproperties is mentioned in the comments. If the user had

Try Catch in SQL Server 2000?

一曲冷凌霜 提交于 2019-12-06 02:54:23
问题 Is it possible using Try-Catch in SQL Server 2000 ? 回答1: No, it is not possible. This was only from Sql Server 2005 Check TRY...CATCH (Transact-SQL) and check the Other Versions 回答2: 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 回答3: Instead you can user @@Error .. check this article about error handling 回答4: @@ERROR is a variable updated by the SQL Server database

T-SQL script - logic issues with timeline

北城余情 提交于 2019-12-06 02:10:21
问题 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

How to run a Job from a Stored Procedure in another server?

点点圈 提交于 2019-12-06 00:03:05
Is it possible to run a Job from a stored procedure located in a different server? If so, how? So why not consider using exec LINKEDSERVERNAME.msdb.dbo.sp_start_job 'Job Name' ? (didn't test it though, maybe some-unseen-answer was the same, but erased as incorrect and not working) There must be enough privileges for linked-server-login to run the job, of course - at least it has to be job's owner. Yep, you can use the evil that is osql: osql -S "Remote Server" -E -Q"exec msdb.dbo.sp_start_job 'Job Name'" (Where -E denotes using a trusted connection, you can also specify credentials using

Why are parameters slower than literal values in a where clause?

夙愿已清 提交于 2019-12-05 21:24:58
Situation: c#, sql 2000 I have a table, lets call it 'mytable' with 30 million rows. The primary key is made up of fields A and B: A char(16) B smallint(2) When i do a search like this, it runs really slowly (eg it does a full tablescan) string a="a"; int b=1; string sql = "select * from table(nolock) where a=@a and b=@b"; using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@a", a); cmd.Parameters.AddWithValue("@b", b); using (SqlDataReader rdr = cmd.ExecuteReader()) {...} } Change it to this however, and it runs really quick (eg it hits the index): string where =

Crosstab Query in SQL Server 2000

时光怂恿深爱的人放手 提交于 2019-12-05 21:07:53
I am hoping that someone has attempted this before and I can get some advice before I go any further. I am looking to produce something similar to a crosstab query in sql-server 2000. I have a table structure similar to the following: Item Item_Parameter Parameter id item_id id desc parameter_id desc value What I am looking to do is to flatten out the data through a query/stored procedure to make building reports easier. The ideal solution would produce results such as: Parameter.desc[0] Parameter.desc[1] Parameter.desc[3]... item.id[0] Item_Parameter.value Item_Parameter.value Item_Parameter

The multi-part identifier could not be bound again

久未见 提交于 2019-12-05 19:39:06
I am trying to create a stored procedure like this, CREATE PROCEDURE [dbo].[SP_Name] ( @ID varchar(50), @URL varchar(256) ) AS SELECT DISTINCT Table1.CID, Table2.Name, Table2.aID, Table2.bID, Table3.SchemeName, Table2.cURL FROM Table4 INNER JOIN Table5 ON Table5.eID = Table1.eID INNER JOIN Table2 ON Table2.ID = Table1.CID INNER JOIN [Table3] ON Table3.aID = Table2.aID AND Table3.bID = Table2.bID WHERE Table5.ID = @ID AND Table2.cURL LIKE '%' + @URL + '%' but I'm getting this error: Msg 4104, Level 16, State 1, Procedure SP_Name, Line 7 The multi-part identifier "Table1.eID" could not be bound.

How to find date ranges in records with consecutive dates and duplicate data

时间秒杀一切 提交于 2019-12-05 17:46:25
There's probably any easy solution for this, but I can't see it. I have a table with consecutive dates and often duplicate associated data for several of these consecutive dates: Date Col1 Col2 5/13/2010 1 A 5/14/2010 1 A 5/15/2010 2 B 5/16/2010 1 A 5/17/2010 1 A 5/18/2010 3 C 5/19/2010 3 C 5/20/2010 3 C Using MS T-SQL, I wish to find the start and end dates for each run of distinct Col1 and Col2 values: StartDate EndDate Col1 Col2 5/13/2010 5/14/2010 1 A 5/15/2010 5/15/2010 2 B 5/16/2010 5/17/2010 1 A 5/18/2010 5/20/2010 3 C Assumptions: There are never any missing dates. Col1 and Col2 are

ASP Classic - Recordset Object vs. Command Object

痞子三分冷 提交于 2019-12-05 17:09:56
I am using ASP Classic and SQL Server 2000 to create dynamic websites. I am a bit confused about when to use a recordset object and when to use a command object when querying the database. I was told that if the stored procedure would be returning records from a SELCT statement then I should use a recordset, however if I am up updating or inserting then I should use a command object and pass all data as parameters to the stored procedure. When using a recordset I often pass any required data like so: rs.Source = "spTest " & id I alway validate the data that I am passing to make sure it is what