sql-server-2000

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

♀尐吖头ヾ 提交于 2019-12-10 08:52:00
问题 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

Why does TSQL on Sql Server 2000 round decimals inconsistently?

你离开我真会死。 提交于 2019-12-10 08:46:59
问题 I'm trying to calculate percent off values for dollar amounts. At 50%, sometimes you get half a penny, and I need to round it to the nearest cent. In Sql, my calculation is as follows: round(retail * 0.5, 2, 0) If I take the following values I get different results: 4.39 2.49 Unrounded I get: 4.39 --> 2.195 2.49 --> 1.245 When rounded I get: 2.195 --> 2.19 1.245 --> 1.25 I'm told this is a form of "banker's rounding", but it seems like the value that is affecting the rounding direction is the

How to write a recursive query in SQL Server 2000

北城余情 提交于 2019-12-10 00:12:42
问题 I have a table which has a list which looks like this References R. Name LineNo. References A 1.1 (B,24.1) A 6.3 (A, 1.3), (D, 22.1) B 23.1 (A. 1.2) B 24.1 (B,23.1) C 2 (A, 1.1) D 3.12 (A, 6.3) The query should go one by one in the records and generate a value based on the references, pick first one lets say, which is Report Name A, Line No. 1.1, Now the reference is (B, 24.1), which means we need to find Report Name B, line no 24.1 and pick its value. In the same table R.Name B and Line No B

SQL Server 2000 - Breaking a query up into 15 minute blocks

◇◆丶佛笑我妖孽 提交于 2019-12-09 19:24:32
问题 I have a continous time dataset and I want to break it up into 15 minute blocks using sql. I don't want to have to create a new table to be able to do this if I can help it. i.e. Time, Count 09:15, 1 09:30, 3 09:45, 0 10:00, 2 10:15, 3 ..... Does anyone have any idea of how I can do this. I presume that is use a select similar to the following: SELECT [Some kind of data manipulation on "MyDate"] , COUNT(ID) FROM MyTable GROUP BY [Some kind of data manipulation on "MyDate"] 回答1: With careful

Update table inserting VARBINARY data

試著忘記壹切 提交于 2019-12-09 14:19:35
问题 When I run the sql query I got something like this : Disallowed implicit conversion from data type varchar to data type varbinary.... Use the CONVERT function to run this query. (severity 16)` The data I want to insert looks like '00001200000000000010000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...FFF' How to done this query? Query looks like : UPDATE <table> SET VARBINARY_DATA = '00001200000000000010000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF....' WHERE ID = 12 回答1: From SQL Server

How can I get the ID of the last INSERTed row using PDO with SQL Server?

我与影子孤独终老i 提交于 2019-12-09 05:39:34
问题 Under other circumstances I might be tempted to use $result = mssql_query("INSERT INTO table (fields) VALUES (data); SELECT CAST(scope_identity() AS int)"); but as I will be inserting user-submitted data, I want to continue to use PDO, which returns an empty array. Unfortunately, I'm running PHP on a Linux server and using dblib to interface with Microsoft SQL Server, which doesn't support PDO::lastInsertID() . Please help! Update to include code example Here's the code I'm using: col1 is a

TSQL to know database role members

余生颓废 提交于 2019-12-08 18:09:04
问题 I am using SQL 2000 and SQL 2005. I want to know which logins have db_owner or db_accessadmin rights to which databases. I can click on users or database roles in every database to see that. Could this be done in an easier way using TSQL? Thanks in advance 回答1: For SQL 2000 and still works for SQL 2005 too SELECT USER_NAME(memberuid), USER_NAME(groupuid) FROM sys.sysmembers WHERE USER_NAME(groupuid) IN ('db_owner', 'db_accessadmin') 回答2: It's sloppy and there is probably a better way, but

How to select only numeric values

大城市里の小女人 提交于 2019-12-08 15:11:23
问题 Table1 id 01 wire 02 steve ram123 03 .... from the table1 i want to select only numeric values, It should not display alphanumeric values like (ram123) Expected Output 01 02 03 .... How to make a query for this condition 回答1: Try ISNUMERIC SELECT * FROM Table1 WHERE ISNUMERIC([ID]) = 1 SQLFiddle Demo 回答2: SELECT * FROM @Table WHERE Col NOT LIKE '%[^0-9]%' 回答3: Just want to note that IsNumeric() has some limitations. For example all of the below will return 1. SELECT ISNUMERIC(' - ') SELECT

In SQL Server 2000 how do you add 0's to beginning of number to fill nchar(n)

耗尽温柔 提交于 2019-12-08 13:41:35
I'm trying to add 0's to the beginning of an nchar(n) . Is their a format function in SQL Server 2000 to add 0's to an int so that it will always have n number of digits with leading 0's: example int nchar(n) 1 0000..1 2 0000002 3 0000003 ... 10 0000010 11 0000011 ... 100 0000100 ... 1000 0001000 e.g. for n=12 DECLARE @foo bigint DECLARE @bar bigint SET @foo=12345678901 SET @bar=12 SELECT RIGHT('000000000000' + CAST(@foo AS VARCHAR(12)),12) SELECT RIGHT('000000000000' + CAST(@bar AS VARCHAR(12)),12) Beware! This won't work for numbers with more than n digits! Sorry for being slightly off-topic

Select minimum number from column which not exist

我与影子孤独终老i 提交于 2019-12-08 12:00:30
问题 I have in my column (id) values 4 5 10 I want to choose minimum nubmer which not exists. Example value 1 then 2 then 3 and then 6..... i'm trying this code IF not EXISTS(SELECT min(id) from table1) select... 回答1: Create a numbers table in your database, then it's easy: SELECT MIN(Numbers.n) As MinMissingId FROM [Numbers] WHERE NOT EXISTS ( SELECT 1 FROM dbo.TableName t WHERE Numbers.n = t.ID ) Here's a small script that creates the table copied from Aaron's article: SELECT TOP (1000000) n =