Category "sql-server-2012"

DISTINCT with HASH MATCH (Flow Distinct) in SQL Server

Recently, while working in SQL Server, I got an interesting thing that removing DISTINCT keyword actually decreased my query performance and increased my search

How do I do a multiple level Nested Loop Join?

I'm sure this must be a common coding question, but I don't even know what to call it. For any given Person, I want to find their team - now there may be teams

Deadlock in SQL Server in simple update operation

I have a SQL command like this: UPDATE tableName SET ColA = @ColA, ColB = @ColB, ColC = @ColC WHERE ID = @ID which is executed as the sole command in its ow

Is there any way to track changes from views in MS Sql Server?

I'm looking for how to track changes from a view in MS Sql-Server 2012. And, the role of the log-in user is Public. So, it's hard to do it. For example, Assumi

Alternative for Cartesian and Cross Join

I want to output all the possible combination in two tables without using cartesian join or cross join. Is this possible?

Pivot data based on category and date field

I have to identify the records with check_in category of S1, T1 and P1 in the check-in-order and pivot the rest of the data until we hit the next category. I wa

SQL Server 2012 Random string from a list

say I have 3 values, Bill, Steve, Jack. and I want to randomly update a table with those values, eg Update contacts set firstname = ('Bill','Steve','Jack') whe

Default row order in SELECT query - SQL Server 2008 vs SQL 2012

Our team recently upgraded our databases from SQL Server 2008 to SQL Server 2012. One breaking change we noticed was in the default order of rows returned by th

Cannot continue the execution because the session is in the kill state. while building clustered index

I get the following error while trying to create a clustered index The statement has been terminated. Msg 596, Level 21, State 1, Line 0 Cannot continu

Join two tables and return only one row from second table

I have two tables. Both tables contains an ID that can be used to join them together. However, table 2 can have more than one row for the same ID. Table 1 will

How to insert into a table that specifies a DEFAULT value for every column?

I have a table where all columns are auto-populated whenever an insertion happens: CREATE TABLE … ( ItemID INT NOT NULL IDENTITY(…

SSMS 2012: Convert DATETIME to Excel serial number

I can't seem to find an answer to this anywhere --- I want to convert a datetime in SQL to the excel serial number. I'm essentially looking for the DATEVALUE f

Export database schema into XML file

I would like to export whole database schema to XML file. Information there what are needed. tables - columns, data type, pk, fk, views - returned columns, fun

SQL Server Maximum rows that can be inserted in a single insert statment

I want to do a batch insert, similar to this question How to do a batch insert in MySQL What is the limitation is SQL Server on how many rows can be inserted