sql-server-2000

Performant way to get the maximum value of a running total in TSQL

你说的曾经没有我的故事 提交于 2020-01-15 03:08:55
问题 We have a table of transactions which is structured like the following : TranxID int (PK and Identity field) ItemID int TranxDate datetime TranxAmt money TranxAmt can be positive or negative, so the running total of this field (for any ItemID) will go up and down as time goes by. Getting the current total is obviously simple, but what I'm after is a performant way of getting the highest value of the running total and the TranxDate when this occurred. Note that TranxDate is not unique, and due

SQL/C# - Primary Key error on UPSERT

你。 提交于 2020-01-14 13:46:29
问题 UPDATE (simplified problem, removed C# from the issue) How can I write an UPSERT that can recognize when two rows are the same in the following case... See how there's a \b [backspace] encoded there (the weird little character)? SQL sees these as the same. While my UPSERT sees this as new data and attempts an INSERT where there should be an UPDATE. //UPSERT INSERT INTO [table] SELECT [col1] = @col1, [col2] = @col2, [col3] = @col3, [col4] = @col4 FROM [table] WHERE NOT EXISTS -- race condition

SQL query and datetime parameter takes long time to execute

徘徊边缘 提交于 2020-01-14 12:58:12
问题 I have a query which takes datetime as a parameter, what we have observed is that if you supply datetime parameter through a variable, Query takes 2 -3 times more time to execute than if you directly hardcode the parameter, Is there any reason or solution to it Following query takes around 5 mins to return the result Declare @Date as DateTime Set @Date = '01/01/2009' Select * from TempTable where effdate = @Date While as Select * from TempTable where effdate = '01/01/2009' it returns in 10–20

sql server update from select

∥☆過路亽.° 提交于 2020-01-14 03:54:13
问题 Following the answer from this post, I have something like this: update MyTable set column1 = otherTable.SomeColumn, column2 = otherTable.SomeOtherColumn from MyTable inner join (select *some complex query here*) as otherTable on MyTable.key_field = otherTable.key_field; However, I keep getting this error: The column prefix 'otherTable' does not match with a table name or alias name used in the query. I'm not sure what's wrong. Can't I do such an update from a select query like this? Any help

Is timestampdiff() in MySQL equivalent to datediff() in SQL Server?

牧云@^-^@ 提交于 2020-01-13 09:40:08
问题 I am working on migrating functions from SQL Server 2000 to MySQL. The following statement executed in SQL Server 2000, gives the output as 109. SELECT DATEDIFF(wk,'2012-09-01','2014-10-01') AS NoOfWeekends1 The equivalent query of in mysql uses timestampdiff() instead of datediff and gives the output as 108. SELECT TIMESTAMPDIFF(WEEK, '2012-09-01', '2014-10-01') AS NoOfWeekends1 I need the output to match when executed in MySQL, so it returns 109. 回答1: I think this could be caused by one of

How i can get the first 3 digits in 123456 Numbers in sql?

梦想的初衷 提交于 2020-01-13 08:28:12
问题 I have field called CallingParty in My CDR table it contains data like this CallingParty 267672668788 I want to select the first 3 number of each of those numbers like CallingParty 267 回答1: if CallingParty is of type int: SELECT CAST(LEFT(CallingParty, 3) AS INT) From CDR 回答2: SQL Server has a Left() function, but it works best on strings. (varchar/char in SQL) Select left(cast(267672668788 as varchar), 3) 回答3: Use this query: SELECT SUBSTRING(CAST(CallingParty AS VARCHAR(50)), 1, 3) FROM

How to use LIKE clause with IN caluse in Sql Server?

本秂侑毒 提交于 2020-01-11 06:24:11
问题 I want to use LIKE clause and IN clause together. e.g: Currently my query is - SELECT * FROM [USER_DETAILS] WHERE [NAME] LIKE 'Dev%' OR [NAME] LIKE 'Deb%' OR ...... ...... How can i use IN clause to achieve this? Can someone please help? :) 回答1: Put the parameter values in a table, then use a single JOIN condition e.g. SELECT * FROM [USER_DETAILS] AS U1 INNER JOIN Params AS P1 ON U1.[NAME] LIKE P1.param + '%'; 回答2: Agree with NullUserException - there is no such syntax. "In" is "syntax sugar"

SQL Server Management Studio: Import quietly ignoring 99.9% of data

独自空忆成欢 提交于 2020-01-10 22:22:27
问题 The Problem i'm trying to import data into a table using SQL Server Management Studio's Import Data task. It only brings in 26 rows, out of the original 49,325. ( Edit : That's where 99.9% comes from: (1-26/49325)*100 = 99.9% Using DTS in Enterprise Manager correctly brings all 49,325 rows. Why is SSMS not importing all rows, reporting that it transferred 49,325 successfully, and experienced no errors? Why is Enterprise Manager able to correctly import all 49,325 rows? Microsoft SQL Server

How can I obtain an Active Directory Group name from a SQL Server stored SID?

我们两清 提交于 2020-01-10 05:12:50
问题 This is a follow-up of a question I asked earlier this morning (posted here.) Following the instructions provided, I've managed to query my SQL Server 2000 database for a SID associated with an AD Group. The SID, however, looks like this: 0x0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01234567 What can I do to obtain the name of the AD Group referenced by the SID? I've tried googling PowerShell scripts, however, most of their examples of SIDs look like this: S-1-5-21-1454471165-1004335555

Calendar Table - Week number of month

走远了吗. 提交于 2020-01-08 13:24:06
问题 I have a calendar table with data from year 2000 to 2012 (2012 wasn't intentional!). I just realize that I don't have the week number of month (e.g In January 1,2,3,4 February 1,2,3,4) How do I go about calculating the week numbers in a month to fill this table? Here is the table schema CREATE TABLE [TCalendar] ( [TimeKey] [int] NOT NULL , [FullDateAlternateKey] [datetime] NOT NULL , [HolidayKey] [tinyint] NULL , [IsWeekDay] [tinyint] NULL , [DayNumberOfWeek] [tinyint] NULL ,