sql-server-2000

SQL Server 2000 TOP and OUTPUT keywords

大兔子大兔子 提交于 2019-12-25 02:35:12
问题 This query works great in SQL Server 2005 and 2008. How would I write it in SQL Server 2000? UPDATE TOP 10 myTable SET myBooleanColumn = 1 OUTPUT inserted.* Is there any way to do it besides running multiple queries? 回答1: To be honest, your query doesn't really make sense, and I have a hard time understanding your criteria for "great." Sure, it updates 10 rows, and doesn't give an error. But do you really not care which 10 rows it updates? Your current TOP without ORDER BY suggests that you

auto incrementing id in sql server

梦想的初衷 提交于 2019-12-24 21:19:49
问题 How to auto increment an id in SQL Server whenever a new row is inserted in the table? This id is primary key of the table. 回答1: You're looking for IDENTITY. e.g. CREATE TABLE MyTable ( ID INTEGER IDENTITY(1,1) PRIMARY KEY, FieldA VARCHAR(10) ) The ID field will auto increment, starting at 1 and increasing by one each time. 回答2: And to return the id in your code lookup scope_identity() and the OUTPUT clause. De not use @@identity as it can return the wrong value if triggers are put on the

SQL query result monthly arrangement

爷,独闯天下 提交于 2019-12-24 19:09:47
问题 I have two tables (1) MonthlyTarget {SalesManCode, TargetValue}; (2) MonthlySales {SalesManCode, SaleDate, AchievedValue}; I have to make a query that produces a result like the following table: {SalesManCode, JanTar, JanAch, FebTar, FebAch,....., DecTar, DecAch} What should be the query? 回答1: What database are you using? I have a stored procedure that simplifies doing that type of pivot for Microsoft SQL Server 2005 ... If you are using SQL Server 2005: Run this to install the pivot_query

select all databases in sysobjects that have a table named 'mytable' regardless of schema?

时间秒杀一切 提交于 2019-12-24 12:47:37
问题 For a given sql 2000 - 2008 server I want to find any table named dbo.[MyTable] on that server. In addition, how do I find all databases that have a table named [dbo].[MyTable] and [AnySchemaName].[MyTable]. Is there a simple sp_ command like spTables MyTable? Or 'sp_AllDatabaseTable [MyTable]'? I want to print it out like: ServerName Database SchemaName MyTable Date Created ----------- --------- ----------- --------- ------------- Thx 回答1: Of course, you can use sp_msforeachdb for this

How to find the total between the dates for each values

丶灬走出姿态 提交于 2019-12-24 12:43:18
问题 Table1 Period datefrom dateto code id 01/2012 18/12/2011 28/12/2011 A Emp1 01/2012 11/01/2012 14/01/2012 B Emp1 02/2012 20/12/2011 25/12/2011 A Emp2 02/2012 01/02/2012 08/01/2012 B Emp2 'from and to date is greater than current date. ..... i want to take total of value between datefrom and dateto with system date validation Expected Output ID PERIOD A B TOTAL Emp1 01/2012 11 4 15 Emp2 02/2012 6 0 6 'B is 0 because from and to date is greater than current date. How to make a query for this

Longest prefix match in SQL Server 2000

久未见 提交于 2019-12-24 10:44:31
问题 I have 2 tables. lets just say its records and numbers the records.number contains a number which I want to find the longest possible associated prefix in numbers.prefix in SQL Server 2000 How would I go about doing this? e.g. records.number = '0841234567' numbers.prefix = '084' '0841' '08412' I would want to select 08412 回答1: select top 1 N.Prefix from Numbers as N inner join Records as R on R.Number like N.Prefix+'%' order by len(N.Prefix) desc Update. The longest prefix for each number in

How can I cure parameter sniffing on SQL Server 2000?

烈酒焚心 提交于 2019-12-24 10:22:31
问题 I am having an issue where an update query with about 70 parameters times-out on occasion. Based on some research, I believe this is due to packet sniffing. I saw that in newer versions of SQL Server, I can use the Option(recompile) clause, but that does not work in my case, since I am using server 2000. I am using sqlhelper.executeNonQuery and not a stored procedure. 回答1: An easy fix is not to use parameters. Instead of: SELECT * FROM YourTable WHERE UserName = @myUserName; Pass: SELECT *

SQL 2000, some functions from client side not working

為{幸葍}努か 提交于 2019-12-24 09:17:14
问题 I create a query: Select * from HR_Tsalary where month='3' and year ='2010' the result is 473 records and I found 2 duplicate record, then I create another query to find duplicate record only: SELECT Emp_No, COUNT(*) FROM HR_Tsalary WHERE year = '10' AND month = '3' GROUP BY Emp_No HAVING COUNT(*) > 1 the result is zero record from client side thru Visual Basic Adodb code. When I use same query from server the result is 2 records. Is there any different between when create a query from server

Retrieve data from xml file and insert into database table

此生再无相见时 提交于 2019-12-24 08:46:52
问题 I am using c# .net 1.1 and SQL Server 2000.... I want to retrive data from an xml file and store that data into the database table. XML file: <information> <data> <id="1"></id> <name>peter</name> <age>25</age> </data> </information> My databse table is id int, name varchar(100), age int 回答1: First off - your XML is invalid: <data> <id="1"></id> This is not a valid XML construct - what should it be?? An "ID" attribute on the data node? <data id="1"> An "ID" element with the value inside? <data

II6 File Upload in MVC storing as 0x0000…in SQL Database

末鹿安然 提交于 2019-12-24 08:46:50
问题 I'm having a bit of an issue uploading files to a database. I'll post snippets of my code below. The table i'm uploading to has the following structure: [IDEnsayo] int NOT NULL, [Nombre] varchar(256) NULL, [Tipo] varchar(256) NULL, [Longitud] int NULL, [Contenido] image NULL This is the class public class Archivo { public string Nombre { get; set; } public string Tipo { get; set; } public long Longitud { get; set; } public byte[] Contenido { get; set; } } I can upload the file using my