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
1 answer

DateDiff - DST issue

Background I have a scenario where I am calculating the difference between two dates. While the increment differences are spot on, the final calculation has introduced a 60 minute (1 hour) disparity. After investigation and "hair pulling"…
GoldBishop
  • 2,820
  • 4
  • 47
  • 82
3
votes
1 answer

How can I use XQuery to update an attribute value in an XML variable?

Trying to update one attribute in the XML contained in a variable: set @x.modify('declare namespace abc="http://abcsystems.com/"; replace value of (/abc:App/abc:Client/abc:Addresses/abc:PostalAddress)[@AddressLine1] with "555 Service Rd."') Tried…
ajeh
  • 2,652
  • 2
  • 34
  • 65
3
votes
1 answer

Group dates by 7 days excluding specific dates

I need query, where I could group dates by every 7 days from beginning of the month. The problem is I have to exclude some days, specifically days before/after holidays and holidays. In my DateDay dimension there's a column, thats indicates which…
Dodzik
  • 360
  • 9
  • 24
3
votes
2 answers

(SQL) Identify positions of multiple occurrences of a string format within a field

I need to split a narrative field (free text) into multiple rows. Format is currently along the lines of: Case_Reference | Narrative ```````````````|````````````````````````````````````` XXXX/XX-123456 | [Endless_Text up to ~50k characters] Within…
Lorielus
  • 81
  • 1
  • 6
3
votes
1 answer

Compare two most recent columns for same ID

I have a table for persons’ addresses. The Class column tells whether it is a home (H), postal (P) or internal (I) address. Each time a person updates the address, the date is stored as well. The internal address is used by my company when a…
Marcos O
  • 33
  • 2
3
votes
3 answers

Can not order by alias in SQL Server 2012

I am using SQL Server 2012, version 11.0.3000.0. I have a query like this: SELECT BAUSER.USER_FNM + ' ' + BAUSER.USER_LNM AS USER_FULL_NAME FROM CAORAC CAORAC INNER JOIN CAACCO CAACCO …
FrenkyB
  • 6,625
  • 14
  • 67
  • 114
3
votes
2 answers

Get the count of days across multiple rows

This is for SQL Server 2008/2012. I have the following dataset with the claim start date and end date. I want to calculate the number of days when there are back to back claims where the claim start date of the next date is one day after the claim…
Sanket J
  • 187
  • 1
  • 1
  • 12
3
votes
4 answers

Condition to COMPARE TWO DATE From parameter and ADD if it Satisfies

This is MY procedure , Im getting from and to date in the procedure i have to check if difference between FROM and TO date is greater than 2 if the condition satisfies i have to add 2days in from days and set it as TODATE ALTER PROCEDURE…
3
votes
1 answer

How to parse XML column in SQL Server 2012?

I have never used XML parsing in SQL Server, I would like to extract the fields in its own column, get the correct data. I have a column called CustomerHeaderUncompressed in a Customer table that looks something like below, how do I extract the…
Moni singh
  • 39
  • 1
  • 2
3
votes
1 answer

Sales Targets using running totals with resets SQL Server 2012

I'm using SQL Server 2012 to extract rolling sales info for sales agents. These agents are paid bonuses if they achieve 15 sales within a rolling time period of 6 or less days. If they make target, the rolling count resets. Sundays should be…
Bob
  • 33
  • 5
3
votes
1 answer

Two columns updating each other on same table through a TRIGGER on SQL Server 2012

Let me try to simplify the issue... I have a table with two columns (A and B) When A is updated, B will have to be updated (using A's new value to perform some calculation) When B is updated, A will have to be updated (using B's new value to…
Porkispin
  • 31
  • 1
3
votes
2 answers

Grouping a table issue

I have the table with four fields: ID, DateBeg, DateEnd, and RankID. RankID value is rank of the ID field over DateBeg asc. here's sample data: ID |RankID | DateBeg | DateEnd | ---|-------|-------------------------- 1 | 1 |01-01-2016 …
Tedo G.
  • 1,556
  • 3
  • 17
  • 29
3
votes
3 answers

Converting string 'yyyy-mm-dd' to date

I want to select from table where date column is equal to specific date which I sending as a string in format 'yyyy-mm-dd'. I need to convert that string and than to compare if I have that date in my table. For now I am doing this: select * FROM…
SeaSide
  • 149
  • 1
  • 3
  • 15
3
votes
0 answers

How to increase Alias length beyond 128?

I am getting a error when I execute the following query : select MaterialTypes as 'Reasons(Polyesters. Unsaturated polyester resins are the simplest,Orthophthalic,Isophthalic,Vinyl ester,Phenolic, Epoxy, Gel coat)' from Material as Msg…
mano
  • 308
  • 3
  • 19
3
votes
1 answer

SQL Server reuse aliases in subqueries

This might sound like a dumb question - apologies, I'm new to SQL Server and I just want to confirm my understanding. I've got a query that is aggregating values in a table as a subquery in different ways for different columns, e.g. for a…
Johnny C
  • 100
  • 1
  • 8