sql-server-2012

Identify sub-set of records based on date and rules in SQL Server

霸气de小男生 提交于 2020-01-13 17:57:00
问题 I have a dataset that looks like this: I need to identify the rows that have Linked set to 1 but ONLY where they are together when sorted by ToDate descending as in the picture. In other words I want to be able to identify these records ( EDITED ): This is a simplified dataset, in fact there will be many more records... The logic that defines whether a record is linked is if the FromDate of a record is within 8 weeks of the ToDate of the preceeding date...but this is testData so may not be

How often are SQL Server Index Usage Stats Updated and what triggers it?

百般思念 提交于 2020-01-13 13:50:49
问题 There are some other similar question to this but, please, do not confuse. I know there's a function STATS_DATE() to know where the stats where updated, which is fine, but what I want to know is what triggers an update of this stats, or a cut-off. I know there's a report for this as well. But last week I saw the stats in certain server and they gave me very good information with amounts of 4 digits for the main tables in this particular database. Right now looking in the same production

How to check blocking queries in SQL Server

爷,独闯天下 提交于 2020-01-12 08:09:30
问题 I have one warehouse server which got data/sync from legacy system 24/7, I noticed some of my reports/sql jobs performance is uncertain and most of the time I heard from DBA team that my query is blocking to other sync process. From DBA team I came to know command i.e. EXEC SP_WHO2 by which I can identify spid of query which cause blocking by looking into column BlkBy. Please suggest me how I can avoid blocking and other ways to check blocking in SQL Server 回答1: Apart from Sp_Who2 you can use

How to check blocking queries in SQL Server

末鹿安然 提交于 2020-01-12 08:09:08
问题 I have one warehouse server which got data/sync from legacy system 24/7, I noticed some of my reports/sql jobs performance is uncertain and most of the time I heard from DBA team that my query is blocking to other sync process. From DBA team I came to know command i.e. EXEC SP_WHO2 by which I can identify spid of query which cause blocking by looking into column BlkBy. Please suggest me how I can avoid blocking and other ways to check blocking in SQL Server 回答1: Apart from Sp_Who2 you can use

Get the position of xml element in SQL Server 2012

吃可爱长大的小学妹 提交于 2020-01-12 04:51:05
问题 How to get the row number for the rows using SQL Server 2012? Here is the xml <Rows> <Row>Coating</Row> <Row>Drying</Row> <Row>Waxing</Row> </Rows> I need data returned like this RowLabel RowNumber ------------------- Coating 1 Drying 2 Waxing 3 回答1: You can use some internal knowledge about how SQL Server implements XML shredding and use row_number() like this. declare @XML xml = '<Rows> <Row>Coating</Row> <Row>Drying</Row> <Row>Waxing</Row> </Rows>' select T.X.value('text()[1]', 'nvarchar

Update a TIMESTAMP column to be nullable

与世无争的帅哥 提交于 2020-01-11 10:57:14
问题 I have a table that exists in two databases. In one database there is a table with a column called ROW_VERSION that is of type TIMESTAMP NOT NULL . In the second database the same table has the same column of type TIMESTAMP but it is of type TIMESTAMP NULL . I would like to change the column in the first database to be nullable. This will allow me to synchronize between the two databases easier. But when I run this: ALTER TABLE [MyTable] ALTER COLUMN ROW_VERSION TIMESTAMP NULL I get the error

Combine two tables in one [closed]

こ雲淡風輕ζ 提交于 2020-01-11 10:50:07
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I have two tables in MSSQL Server 2012 and would like to combine them into one new table. They are linked by the column messageID. The first table ( Message ) has messageID sender date The second table(

Entity Framework and OFFSET/FETCH on Sql Server

自作多情 提交于 2020-01-11 10:36:29
问题 I just encountered a weird bug in my app where a paged data grid contained duplicate rows. Investigation showed that it's because the new paging mechanism Entity Framework uses with Sql Server 2012 as of version 6.1.2 only works on strictly ordered column sets , as is documented here. Since most columns are not strictly ordered (meaning you have duplicate entries with respect to the sort order), simply binding one of the typical grid middlewares to Entity Framework is now broken subtly and

Entity Framework and OFFSET/FETCH on Sql Server

半世苍凉 提交于 2020-01-11 10:36:13
问题 I just encountered a weird bug in my app where a paged data grid contained duplicate rows. Investigation showed that it's because the new paging mechanism Entity Framework uses with Sql Server 2012 as of version 6.1.2 only works on strictly ordered column sets , as is documented here. Since most columns are not strictly ordered (meaning you have duplicate entries with respect to the sort order), simply binding one of the typical grid middlewares to Entity Framework is now broken subtly and

How regular expression OR operator is evaluated

家住魔仙堡 提交于 2020-01-11 08:44:15
问题 In T-SQL I have generated UNIQUEIDENTIFIER using NEWID() function. For example: 723952A7-96C6-421F-961F-80E66A4F29D2 Then, all dashes ( - ) are removed and it looks like this: 723952A796C6421F961F80E66A4F29D2 Now, I need to turn the string above to a valid UNIQUEIDENTIFIER using the following format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and setting the dashes again. To achieve this, I am using SQL CLR implementation of the C# RegexMatches function with this ^.{8}|.{12}$|.{4} regular expression