sql-server-2000

SQL self join multiple times

旧城冷巷雨未停 提交于 2019-12-20 04:16:40
问题 I have a single database table that stores week entries. Id Value WeekId 1 1.0000 1 2 2.0000 1 There can be up to three entries with the same week. So I figured using a self join would solve this SELECT w1.Value, w2.Value, w3.Value FROM [List].[dbo].[testWeekEntries] as w1 LEFT OUTER JOIN [List].[dbo].[testWeekEntries] as w2 ON w1.WeekId = w2.weekId LEFT OUTER JOIN [List].[dbo].[testWeekEntries] as w3 ON w2.WeekId = w3.WeekId WHERE w1.Id < w2.Id AND w2.Id < w3.Id The problem: It worls fine

How to display all the dates between two given dates in SQL

廉价感情. 提交于 2019-12-20 03:14:31
问题 Using SQL server 2000. If the Start date is 06/23/2008 and End date is 06/30/2008 Then I need the Output of query as 06/23/2008 06/24/2008 06/25/2008 . . . 06/30/2008 I Created a Table names as Integer which has 1 Column, column values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 then I used the below mentioned query Tried Query SELECT DATEADD(d, H.i * 100 + T .i * 10 + U.i, '" & dtpfrom.Value & "') AS Dates FROM integers H CROSS JOIN integers T CROSS JOIN integers U order by dates The above query is

How can I update Crate IDs of List of Fruits in single SQL query in c#

谁说胖子不能爱 提交于 2019-12-20 03:11:47
问题 In reference to my question, how can i update SQL table logic I want a query which will do something like this, I my last question was confusing hence I am asking a different question. How can I update Crate IDs of List of Fruits in single SQL query in c# FruitID and CrateID are foriegn keys and will always in other tables. 回答1: Try using IN : UPDATE FRUITS SET CRATE = 'CRATE 7' WHERE FRUITID IN (1, 2, 3) Or UPDATE FRUITS SET CRATE = 'CRATE 7' WHERE FRUITName IN ('Mango1', 'Mango2', 'Apple 6'

Get last inserted UNIQUEIDENTIFIER in SQL Server 2000

不想你离开。 提交于 2019-12-19 17:35:20
问题 The OUTPUT clause is compatible with SQL Server 2005 but not SQL Server 2000. How do I convert this command to work in SQL Server 2000? CREATE TABLE sample ( ID uniqueidentifier NOT NULL DEFAULT newid(), Title varchar(30) NOT NULL ) INSERT INTO sample (Title) OUTPUT INSERTED.ID VALUES ('Test1') I need the command to retrieve the ID since the INSERT command needs to be called from a stored procedure. Thanks for any help! 回答1: DECLARE @uid uniqueidentifier SET @uid = newid() INSERT INTO sample

How to use a single SqlTransaction for multiple SqlConnections in .NET?

独自空忆成欢 提交于 2019-12-19 09:29:17
问题 I have SQL Server 2000, it doesn't support MultipleActiveResults . I have to do multiple inserts, and it's done with one connection per insertion. I want to begin a transaction before all insertions and finish it after all insertions. How do I do it? 回答1: What is the reason you don't use one connection and multiple commands (actually one command recreated in loop)? Maybe this solution will work for you: public static void CommandExecNonQuery(SqlCommand cmd, string query, SqlParameter[] prms)

Executing stored proc from DotNet takes very long but in SSMS it is immediate

给你一囗甜甜゛ 提交于 2019-12-19 06:26:10
问题 I have a stored proc on SQL Server 2000 that takes 3 parameters. When I call the stored proc from DotNet using SqlCommand.ExecuteReader () it takes about 28 seconds. When I run the same query inside SSMS directly it returns immediately. When I take the query out of the stored proc and run it directly using DotNet it also returns immediately. These are the results from a SQL Profiler session SP Inside Dot Net Duration: 28030 Reads: 2663365 Writes: 0 SP Inside SSMS Duration: 450 Reads: 23535

Selecting SUM of TOP 2 values within a table with multiple GROUP in SQL

让人想犯罪 __ 提交于 2019-12-19 05:53:48
问题 I've been playing with sets in SQL Server 2000 and have the following table structure for one of my temp tables (#Periods): RestCTR HoursCTR Duration Rest ---------------------------------------- 1 337 2 0 2 337 46 1 3 337 2 0 4 337 46 1 5 338 1 0 6 338 46 1 7 338 2 0 8 338 46 1 9 338 1 0 10 339 46 1 ... What I'd like to do is to calculate the Sum of the 2 longest Rest periods for each HoursCTR, preferably using sets and temp tables (rather than cursors, or nested subqueries). Here's the

Selecting SUM of TOP 2 values within a table with multiple GROUP in SQL

こ雲淡風輕ζ 提交于 2019-12-19 05:52:35
问题 I've been playing with sets in SQL Server 2000 and have the following table structure for one of my temp tables (#Periods): RestCTR HoursCTR Duration Rest ---------------------------------------- 1 337 2 0 2 337 46 1 3 337 2 0 4 337 46 1 5 338 1 0 6 338 46 1 7 338 2 0 8 338 46 1 9 338 1 0 10 339 46 1 ... What I'd like to do is to calculate the Sum of the 2 longest Rest periods for each HoursCTR, preferably using sets and temp tables (rather than cursors, or nested subqueries). Here's the

classic ASP protection against SQL injection

烈酒焚心 提交于 2019-12-19 04:06:13
问题 I've inherited a large amount of Classic ASP code that is currently missing SQL injection protection, and I'm working on it. I've examined in detail the solutions offered here: Classic ASP SQL Injection Protection On the database side, I have a Microsoft SQL server 2000 SP4 Unfortunately stored procedures are not an option. After studying php's mysql_real_escape_string ( http://www.w3schools.com/php/func_mysql_real_escape_string.asp ) , I've replicated its functionality in ASP. My question(s)

SQL Server How to output one table result from multiple results with a WHILE query

笑着哭i 提交于 2019-12-19 03:42:17
问题 From this answer: Is there a way to loop through a table variable in TSQL without using a cursor? I'm using the method WHILE EXISTS(SELECT * FROM #Temp) The problem is that it's outputting multiple tables, if possible I'd like to output as a single table. Declare @Id int WHILE EXISTS(SELECT * FROM #Temp) Begin Select Top 1 @Id = Id From #Temp --Do some processing here Delete #Temp Where Id = @Id End So right now it outputs this: x y -- -- 1 a x y -- -- 1 b But I'd like it to output this: x y