sql-server-2000

MSSQL: Update statement avoiding the CHECK constraint

假如想象 提交于 2019-11-30 17:26:49
问题 Working in MS2000, I have a table called JobOwners that maps Jobs (JPSID) to the Employees that own them (EmpID). It also contains the date they started owning that job (DateStarted), date they stopped owning that job (DateEnded) and if the ownership is active (IsActive). Looks like this. CREATE TABLE JobOwners ( LogID int NOT NULL IDENTITY(1,1) PRIMARY KEY, JPSID int NOT NULL FOREIGN KEY REFERENCES JobsPerShift(JPSID), EmpID int NOT NULL FOREIGN KEY REFERENCES Employees(EmpID), DateStarted

There is already an object named '##Temp' in the database

孤街醉人 提交于 2019-11-30 16:42:50
问题 I have a stored procedure on SQL Server 2000. It contains: select ... into ##Temp ... ... drop table ##Temp When I run the stored procedure with ADO a second time, it prompts: There is already an object named '##Temp' in the database. Could anyone kindly tell me what's wrong? 回答1: You should re-write your stored proc to drop the temp table if it exists, then you won't ever have this issue IF (SELECT object_id('TempDB..##Temp')) IS NOT NULL BEGIN DROP TABLE ##Temp END 回答2: You are using a

Execute stored procedure from a Trigger after a time delay

穿精又带淫゛_ 提交于 2019-11-30 14:30:13
I want to call stored procedure from a trigger, how to execute that stored procedure after x minutes? I'm looking for something other than WAITFOR DELAY thanks Have an SQL Agent job that runs regularly and pulls stored procedure parameters from a table - the rows should indicate also when their run of the stored procedure should occur, so the SQL Agent job will only pick rows that are due/slightly overdue. It should delete the rows or mark them after calling the stored procedure. Then, in the trigger, just insert a new row into this same table. You do not want to be putting anything in a

Prevent a Stored Procedure from being executed twice at the same time

本秂侑毒 提交于 2019-11-30 14:21:04
I have a stored procedure for SQL Server 2000 that can only have a single instance being executed at any given moment. Is there any way to check and ensure that the procedure is not currently in execution? Ideally, I'd like the code to be self contained and efficient (fast). I also don't want to do something like creating a global temp table checking for it's existence because if the procedure fails for some reason, it will always be considered as running... I've searched, I don't think this has been asked yet. If it has been, sorry. yes there is a way. use what is known as SQL Server

Efficient Paging (Limit) Query in SQLServer 2000?

你说的曾经没有我的故事 提交于 2019-11-30 13:58:34
问题 What would be the most efficient way to do a paging query in SQLServer 2000? Where a "paging query" would be the equivalent of using the LIMIT statement in MySQL. EDIT: Could a stored procedure be more efficient than any set based query in that case? 回答1: Paging of Large Resultsets and the winner is using RowCount. Also there's a generalized version for more complex queries. But give credit to Jasmin Muharemovic :) DECLARE @Sort /* the type of the sorting column */ SET ROWCOUNT @StartRow

Wrong week number using DATEPART in SQL Server

▼魔方 西西 提交于 2019-11-30 13:55:07
I've got the problem that select datepart(ww, '20100208') is returning as result week 7 in SQL Server 2000. But 08.02.2010 should be week 6 according to the ISO 8601 specification! This is causing problems in delivery week calculations. What should I do to get week number values according to ISO 8601? AdaTheDev You can do this within SQL 2008 very easily as it now supports isoww as the first datepart argument. However, this wasn't in SQL 2000 (or 2005). There is a function in this article which will do it for you in SQL 2000/2005. In case the blog goes offline, here is the function. Go to the

Is there a way to persist a variable across a go?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 13:06:21
问题 Is there a way to persist a variable across a go? Declare @bob as varchar(50); Set @bob = 'SweetDB'; GO USE @bob --- see note below GO INSERT INTO @bob.[dbo].[ProjectVersion] ([DB_Name], [Script]) VALUES (@bob,'1.2') See this SO question for the 'USE @bob' line. 回答1: The go command is used to split code into separate batches. If that is exactly what you want to do, then you should use it, but it means that the batches are actually separate, and you can't share variables between them. In your

Does size of a VARCHAR column matter when used in queries [duplicate]

北城以北 提交于 2019-11-30 08:37:45
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: is there an advantage to varchar(500) over varchar(8000)? I understand that a VARCHAR(200) column containing 10 characters takes same amount of space as a VARCHAR(20) column containing same data. I want to know if changing a dozen VARCHAR(200) columns of a specific table to VARCHAR(20) would make the queries run faster, especially when: These columns will never contain more than 20 characters These columns are

SQL Server Url Decoding

北城以北 提交于 2019-11-30 08:12:48
问题 I need to run a query against a legacy table that stores URL encoded text. I need this text to be decoded in my results. How do I achieve this? 回答1: Try one of these: CREATE FUNCTION dbo.UrlDecode(@url varchar(3072)) RETURNS varchar(3072) AS BEGIN DECLARE @count int, @c char(1), @cenc char(2), @i int, @urlReturn varchar(3072) SET @count = Len(@url) SET @i = 1 SET @urlReturn = '' WHILE (@i <= @count) BEGIN SET @c = substring(@url, @i, 1) IF @c LIKE '[!%]' ESCAPE '!' BEGIN SET @cenc = substring

How to catch the output of a DBCC-Statement in a temptable

时光毁灭记忆、已成空白 提交于 2019-11-30 08:12:20
I tried the following on SQL-Server: create table #TmpLOGSPACE( DatabaseName varchar(100) , LOGSIZE_MB decimal(18, 9) , LOGSPACE_USED decimal(18, 9) , LOGSTATUS decimal(18, 9)) insert #TmpLOGSPACE(DatabaseName, LOGSIZE_MB, LOGSPACE_USED, LOGSTATUS) DBCC SQLPERF(LOGSPACE); ...but this rises an syntax-error... Any sugestions? Put the statement to be run inside EXEC('') insert #TmpLOGSPACE(DatabaseName, LOGSIZE_MB, LOGSPACE_USED, LOGSTATUS) EXEC('DBCC SQLPERF(LOGSPACE);') This does not directly answer the question, but it does answer the intent of the question: presumably, you want a simple way