tsql

Linq .Contains with large set causes TDS error

試著忘記壹切 提交于 2020-02-03 18:53:58
问题 I've oversimplified this a bit, because I'm looking for a general-purpose answer. Let's say I've got a table setup like this: Parent recno int (unique, pk) date datetime stuff varchar(50) Child parentrecno (int, fk) --- PK sequence (int) --- PK data varchar(50) And in my C# program I've gone through a lot of hassle to find the Parent records that I'm interested in and stuff them into a list. Parent is a really large table, and I'd rather not query it more than necessary. So I squirrel away

How do I get the Identity field that results from an insert?

别等时光非礼了梦想. 提交于 2020-02-03 08:43:29
问题 I'm going to insert data into a table like so: Insert Into MyTable (Field1, Field2) Values ('test', 5) When that insert occurs, the new row is going to have an identify value in the ID column. If have a variable called @ID in my T-SQL code, how do I populate @ID with the result of the T-SQL Insert? Declare @ID int Insert into MyTable (Field1, Field2) Values ('test', 5) --//How do I populate @ID with the value of ID of the record that was just inserted? 回答1: There are two ways - the first is

How do I get the Identity field that results from an insert?

我的梦境 提交于 2020-02-03 08:42:40
问题 I'm going to insert data into a table like so: Insert Into MyTable (Field1, Field2) Values ('test', 5) When that insert occurs, the new row is going to have an identify value in the ID column. If have a variable called @ID in my T-SQL code, how do I populate @ID with the result of the T-SQL Insert? Declare @ID int Insert into MyTable (Field1, Field2) Values ('test', 5) --//How do I populate @ID with the value of ID of the record that was just inserted? 回答1: There are two ways - the first is

split date range into months

别等时光非礼了梦想. 提交于 2020-02-02 12:10:30
问题 I would like to split the date range into respective months. For example - I've a view which has data in the following way: user project startdate enddate ----------------------------------- A abc1 2011-01-01 2011-12-31 A abc2 2011-01-01 2011-05-01 B xyz1 2011-01-01 2011-03-01 I want to be able to display the above data in this way: user project startdate enddate A abc1 2011-01-01 2011-01-31 A abc1 2011-02-01 2011-02-28 A abc1 2011-03-01 2011-03-31 ---------------------------------- A abc2

split date range into months

只愿长相守 提交于 2020-02-02 12:09:25
问题 I would like to split the date range into respective months. For example - I've a view which has data in the following way: user project startdate enddate ----------------------------------- A abc1 2011-01-01 2011-12-31 A abc2 2011-01-01 2011-05-01 B xyz1 2011-01-01 2011-03-01 I want to be able to display the above data in this way: user project startdate enddate A abc1 2011-01-01 2011-01-31 A abc1 2011-02-01 2011-02-28 A abc1 2011-03-01 2011-03-31 ---------------------------------- A abc2

split date range into months

醉酒当歌 提交于 2020-02-02 12:08:07
问题 I would like to split the date range into respective months. For example - I've a view which has data in the following way: user project startdate enddate ----------------------------------- A abc1 2011-01-01 2011-12-31 A abc2 2011-01-01 2011-05-01 B xyz1 2011-01-01 2011-03-01 I want to be able to display the above data in this way: user project startdate enddate A abc1 2011-01-01 2011-01-31 A abc1 2011-02-01 2011-02-28 A abc1 2011-03-01 2011-03-31 ---------------------------------- A abc2

Deletion of rows in table cause LOCKS

 ̄綄美尐妖づ 提交于 2020-02-01 16:03:11
问题 I am running the following command to delete rows in batches out of a large table (150 million rows): DECLARE @RowCount int WHILE 1=1 BEGIN DELETE TOP (10000) t1 FROM table t1 INNER JOIN table2 t2 ON t2.PrimaryKey = t1.PrimaryKey WHERE t1.YearProcessed <= 2007 SET @RowCount = @@ROWCOUNT IF (@RowCount < 10000) BREAK END This table is HIGHLY used. However, it is deleting records, but it is also causing locking on some records, thus throwing errors to the user (which is not acceptable in the

Group by numbers that are in sequence

隐身守侯 提交于 2020-02-01 05:34:29
问题 I have some data like this: row id 1 1 2 36 3 37 4 38 5 50 6 51 I would like to query it to look like this: row id group 1 1 1 2 36 2 3 37 2 4 38 2 5 50 3 6 51 3 ... so that I can GROUP BY where the numbers are consecutively sequential. Also, looping/cursoring is out of the question since I'm working with a pretty large set of data, thanks. 回答1: create table #temp ( IDUnique int Identity(1,1), ID int, grp int ) Insert into #temp(ID) Values(1) Insert into #temp(ID) Values(36) Insert into #temp

Group by numbers that are in sequence

旧街凉风 提交于 2020-02-01 05:34:26
问题 I have some data like this: row id 1 1 2 36 3 37 4 38 5 50 6 51 I would like to query it to look like this: row id group 1 1 1 2 36 2 3 37 2 4 38 2 5 50 3 6 51 3 ... so that I can GROUP BY where the numbers are consecutively sequential. Also, looping/cursoring is out of the question since I'm working with a pretty large set of data, thanks. 回答1: create table #temp ( IDUnique int Identity(1,1), ID int, grp int ) Insert into #temp(ID) Values(1) Insert into #temp(ID) Values(36) Insert into #temp

T-SQL Delete Inserted Records

↘锁芯ラ 提交于 2020-02-01 04:18:35
问题 I know the title may seem strange but this is what I want to do: I have table with many records. I want to get some of this records and insert them in other table. Something like this: INSERT INTO TableNew SELECT * FROM TableOld WHERE ... The tricky part is that I want this rows that I have inserted to be deleted form the origin table as well. Is there a easy way to do this, because the only think that I have managed to do is to use a temporary table for saving the selected records and then