Questions tagged [sql-server-2008-r2]

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

Important Note: Extended support for SQL Server 2008 (including 2008 R2) ended on July 9, 2019.

Microsoft will no longer release security updates for any version of SQL Server 2008. Don't let your infrastructure and applications go unprotected. We're here to help you migrate to current versions for greater security, performance and innovation.

If you are still using 2008 R2 version you should seriously consider upgrading.

SQL Server 2008 R2 (codename Kilimanjaro, version 10.50), released in April 2010, is the successor to SQL Server 2008.

This version of Microsoft SQL Server is the 3rd form to utilize the .Net framework for operating with a database framework.

This product includes:
  • Server/Database/Table Triggers
  • Stored Procedure (SProc) & Functions
  • Database Maintenance processes & features
  • Automated SQL Agent with time triggers

Reference

11320 questions
118
votes
6 answers

Partition Function COUNT() OVER possible using DISTINCT

I'm trying to write the following in order to get a running total of distinct NumUsers, like so: NumUsers = COUNT(DISTINCT [UserAccountKey]) OVER (PARTITION BY [Mth]) Management studio doesn't seem too happy about this. The error disappears when I…
whytheq
  • 34,466
  • 65
  • 172
  • 267
107
votes
6 answers

Calculating distance between two points (Latitude, Longitude)

I am trying to calculate the distance between two positions on a map. I have stored in my data: Longitude, Latitude, X POS, Y POS. I have been previously using the below snippet. DECLARE @orig_lat DECIMAL DECLARE @orig_lng DECIMAL SET…
Waller
  • 1,795
  • 4
  • 18
  • 35
105
votes
4 answers

How to query for Xml values and attributes from table in SQL Server?

I have a table that contains a Xml column: SELECT * FROM Sqm A sample of the xml data of a row would be:
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
104
votes
5 answers

Cannot use UPDATE with OUTPUT clause when a trigger is on the table

I'm performing an UPDATE with OUTPUT query: UPDATE BatchReports SET IsProcessed = 1 OUTPUT inserted.BatchFileXml, inserted.ResponseFileXml, deleted.ProcessedDate WHERE BatchReports.BatchReportGUID = @someGuid This statement is well and fine; until…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
98
votes
9 answers

Rebuild all indexes in a Database

I have a very large SQL Server 2008 R2 database (1.5TB) and will be copying some data from column to column within the same table. I've been told that the schema has a large number of indexes and was wondering if there is a default query or script…
ChrisD
  • 1,099
  • 1
  • 8
  • 6
97
votes
20 answers

Select query to remove non-numeric characters

I've got dirty data in a column with variable alpha length. I just want to strip out anything that is not 0-9. I do not want to run a function or proc. I have a script that is similar that just grabs the numeric value after text, it looks like…
SQL_Noob
  • 1,161
  • 1
  • 9
  • 18
86
votes
3 answers

Is a single SQL Server statement atomic and consistent?

Is a statement in SQL Server ACID? What I mean by that Given a single T-SQL statement, not wrapped in a BEGIN TRANSACTION / COMMIT TRANSACTION, are the actions of that statement: Atomic: either all of its data modifications are performed, or none…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
84
votes
6 answers

SQL Server procedure declare a list

My SQL code is fairly simple. I'm trying to select some data from a database like this: SELECT * FROM DBTable WHERE id IN (1,2,5,7,10) I want to know how to declare the list before the select (in a variable, list, array, or something) and inside…
Alex Doro
  • 981
  • 1
  • 6
  • 9
81
votes
15 answers

How do I find the data directory for a SQL Server instance?

We have a few huge databases (20GB+) which mostly contain static lookup data. Because our application executes joins against tables in these databases, they have to be part of each developers local SQL Server (i.e. they can't be hosted on a…
80
votes
5 answers

How to solve SQL Server Error 1222 i.e Unlock a SQL Server table

I am working in a database where I load data in a raw table by a data loader. But today the data loader got stuck for unknown reasons. Then I stopped the data loader from windows task manager. But then I again tried to load data in the raw table but…
user960340
  • 926
  • 1
  • 7
  • 5
74
votes
11 answers

DateTime fields from SQL Server display incorrectly in Excel

Countless times during the day I am copying and pasting records from SQL Server Management Studio to Excel. My problem is that a DateTime value such as 8/23/2013 4:51:02 PM does not display correctly as shown in the image below even though it…
Andre
  • 1,852
  • 1
  • 16
  • 21
72
votes
3 answers

Connecting to MS SQL Server with Windows Authentication using Python?

How do I connect MS SQL Server using Windows Authentication, with the pyodbc library? I can connect via MS Access and SQL Server Management Studio, but cannot get a working connection ODBC string for Python. Here's what I've tried (also without…
71
votes
7 answers

Import and Export Wizard with Identity Column

I want to move data from one DB to another, while keeping the identity column values in the old DB. When I run the wizard I get a validation error "Failure inserting into the read-only column "ChannelID". Where ChannelID is an identity column on…
Elad Lachmi
  • 10,406
  • 13
  • 71
  • 133
70
votes
10 answers

"This SqlTransaction has completed; it is no longer usable."... configuration error?

I've been working on this for about a day and a half now, and searched numberous blogs and help articles on the Web. I found several questions on SO related to this error, but I didn't think they quite applied to my situation (or in some cases,…
White Island
  • 2,571
  • 4
  • 17
  • 13
70
votes
4 answers

CASE WHEN statement for ORDER BY clause

I am using SQL Server 2008 R2. I want the priority based sorting for records in a table. So that I am using CASE WHEN statement in ORDER BY clause. The ORDER BY clause is as below : ORDER BY CASE WHEN TblList.PinRequestCount <> 0 THEN…
Dev
  • 6,570
  • 10
  • 66
  • 112