Questions tagged [sql-server-2012]

Use this tag for questions specific to the 2012 version of Microsoft's SQL Server.

SQL Server 2012 (codename Denali, version 11.00), released in March 2012, is the successor to SQL Server 2008 R2.

This tag covers questions specific to the 2012 version of the database engine. It is recommended that the tag is also used when tagging questions with this version specific tag.

Programmability topics may include but are not limited to

  • FileTable
  • Semantic search
  • Metadata discovery
  • Ad-hoc Query Pagination
  • Sequence objects
  • Throw statement
  • Conversion functions
    • PARSE
    • TRY_CONVERT
    • TRY_PARSE
  • Date and time functions
    • DATEFROMPARTS
    • DATETIME2FROMPARTS
    • DATETIMEFROMPARTS
    • DATETIMEOFFSETFROMPARTS
    • EOMONTH
    • SMALLDATETIMEFROMPARTS
    • TIMEFROMPARTS
  • Logical functions
    • CHOOSE
    • IIF
  • String functions
    • CONCAT
    • FORMAT
  • Analytic functions
    • CUME_DIST
    • LAST_VALUE
    • PERCENTILE_DISC
    • FIRST_VALUE
    • LEAD
    • PERCENT_RANK
    • LAG
    • PERCENTILE_CONT
17074 questions
3
votes
5 answers

Return id of row that has duplicate data

I am needing to get the row id of rows which have duplicate Select Name from table1 group by Name having count(1) > 1 table1 ID | Name | ClientID ---------------------------- 01 | John | 01 02 | Sam | 01 03 | Sue | 01 04 | John …
Xaedblade
  • 35
  • 1
  • 5
3
votes
4 answers

How do I count the return of selected rows in SQL Server?

I have one select query declared in a variable. Now I want to check if the query returns 0 rows then I have to go with other conditions. I am using SQL SERVER 2012. How do I check the variable if it contains 0 rows. Kindly suggest set @sql =…
3
votes
2 answers

Generate SQL Server CPU usage for last 7 days

I have a requirement to generate CPU usage reports for my SQL server for previous 7 days. I will use a graph to represent it. Also, I have to keep track of top 10 queries which consumed maximum CPU each day. I got one post below but I have few…
PiKa
  • 31
  • 1
  • 2
3
votes
5 answers

Query to select and combine uppermost and lowermost value from tables

We have the following tables on our SQL Server 2012. Table A (data): ID, Description --------------- 1 , Bla 1 2 , Bla 2 3 , Bla 3 Table P (data): ID, ParentID, Name ------------------ 1 , NULL , AAA 2 , 3 , CCC 3 , 1 , XXX Table…
Knots
  • 551
  • 8
  • 19
3
votes
1 answer

Find a constraint column name using INFORMATION_SCHEMA.TABLE_CONSTRAINTS in SQL

I have a primary key constraint set up in a table - "tCustomerSessions" with the name "PK_tCustomerSessions". Below is my query - SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'tCustomerSessions' AND Constraint_Type =…
3
votes
2 answers

SQL Server DATEDIFF Computed Column Between Rows

I currently have a table similar to this - RecordTime Running Fault ----------------------------------------------- 2016-09-15 11:32:01.00 0 202 2016-09-15 11:32:08.00 1 202 2016-09-15…
Jamsandwich
  • 634
  • 1
  • 5
  • 25
3
votes
2 answers

SQL Server pivot query alternative or optimize

So I have these tables: -- tbl_obs id lat lon created ------------------------- 1 1.2 -2.1 2002-08-03 2 1.9 -5.5 2002-08-03 3 1.5 -4.1 2002-08-03 -- tbl_obsdata id name value obs_id --------------------------------- 1 …
Alex
  • 193
  • 1
  • 2
  • 12
3
votes
1 answer

How to return result set along with delete

I am trying to get the record from table QUEUE as well as delete the same record. CREATE TABLE DBO.QUEUE ( QUEUEID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY, SOMEACTION VARCHAR(100) ) Through this query using updlock & readpast I am…
user584018
  • 10,186
  • 15
  • 74
  • 160
3
votes
3 answers

Int field in Winform does not update null values in SQL Server database using C#

In my Winforms C# application, I have fields with Int data type and they are set to accept null values in SQL Server database (allow nulls). In the forms I have some textboxes which are bound to those int data type fields. If I don't enter anything…
ammar
  • 71
  • 9
3
votes
4 answers

SUM GROUP BY giving undesired result

First 12 rows of Table T1: Name Status Duration Todd Active 60 Todd Active 60 Todd Active 60 Todd Schedu 60 Todd Schedu 60 Todd Schedu 120 Todd Schedu 120 Bran Active 30 Bran Active 30 Bran Active 60 Bran …
AS91
  • 527
  • 7
  • 18
3
votes
5 answers

Delta Tracing with Triggers

I'm trying to create a Delta tracing for several tables based on triggers. Im using sql server 2012. To simplify my questions, I would like to look only at the after update trigger. So here is the trace table: CREATE TABLE [dbo].[History]( [Id]…
Jaster
  • 8,255
  • 3
  • 34
  • 60
3
votes
2 answers

Query to find the time difference between successive events

Goal: Return a dataset showing time differences between successive events of the same type Table Structure: CREATE TABLE [dbo].[Event]( [EventID] [int] IDENTITY(1,1) NOT NULL, [JobID] [int] NOT NULL, --FK to Job Table [LastRun] [datetime] NOT…
Vorpal Swordsman
  • 393
  • 1
  • 5
  • 14
3
votes
1 answer

How to stop SQL Server or take event based custom action using Extended Events feature

This is regarding SQL Server Extended Events feature which got introduced with SQL Server 2008 and got a GUI interface in version 2012. In specific to its so many wonderful features I also read it here that you can also stop the SQL Server when you…
RBT
  • 24,161
  • 21
  • 159
  • 240
3
votes
1 answer

Getting terrible performance on newly created views

My team is moving several hundred database objects from our QA server to our UAT server. All of the new objects are in two schemas that don't yet exist on the UAT database. The first thing we do upon creating all these objects is run some very…
3
votes
2 answers

SQL Server Query not working when executed from PHP

I've got a set of triggers in my table in SQL Server and when I execute the queries in SQL Server Management Studio they work fine. But when they're executed from my php files they doesn't take effect. I used SQL Server Profiler and the trigger gets…
patricia
  • 1,075
  • 1
  • 16
  • 44
1 2 3
99
100