Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 52150

All versions of Microsoft SQL Server (not MySQL). Please also add a version-specific tag, like sql-server-2016, since it is often relevant to the question.

3 votes

How to select multiple columns but only group by one?

Note: This answer is intended as a supplement to @Lukas Eder's answer If there are multiple values present for the fields SELECTed but a field you wish to GROUP BY, you could instead grab the top mat …
mpag's user avatar
  • 968
1 vote
0 answers
1k views

Database corruption extends beyond nonclustered index issue in SQL Server

Background I have a server running SQL Server 2008 R2 on the matching MS OS. Over the last few months this server had a RAID drive failure on two separate occasions (which simply required hotswapping …
mpag's user avatar
  • 968
3 votes

Using TOP in INSERT INTO statement

And is it correct to assume that the n rows that are chosen from table_name2 are completely random records? When an order isn't specified, it will usually use the sort fields and directions fro …
mpag's user avatar
  • 968
3 votes

.bat file works manually, but does nothing in SQL Server Agent job

By default configuration, SQL Server Agent doesn't run under the same user account as you log in to SSMS. For example, my "SQL Server Agent" system service runs under an sqlagent user account. The "SQ …
mpag's user avatar
  • 968
0 votes

Finding stored procedures with missing indexes

Augmenting @Aaron Bertrand's post by adding in general query index optimization (and auto-generating the DDL for the new indicies) as per @Rory's answer here: https://stackoverflow.com/a/26060183/4228 …
mpag's user avatar
  • 968
1 vote
0 answers
117 views

Threadsafe/non-clobbering foreach file container for SSIS?

I'm attempting to modify a SSIS package in Visual Studio's "File Reader Integration Services" to process multiple ForEach File Enumerators at the same time (each for different file sub-types), but it …
mpag's user avatar
  • 968
2 votes
2 answers
101 views

Basic RDBMS table relations

If you have a design of a "master table" and several "subtables", is it better* that the master table "link" to each of the sub tables, the subtables link to the master, or for bi-directional links be …
mpag's user avatar
  • 968
1 vote

Simple yet problematic update query

Do you have a key/index on SUVillageID in VillageSU? If not, you'll want to add that. Also, have you tried this yet: with ctesuv as (select SUVillageID as VillageID from VillageSU …
mpag's user avatar
  • 968
0 votes

Generate JSON with property names that include dot using SELECT FOR JSON

One solution is to create your own escape sequence, and then use procedural T-SQL with @variables, rather than pure relational query language. Given the inability to directly escape characters in stri …
mpag's user avatar
  • 968
1 vote

Generate JSON with property names that include dot using SELECT FOR JSON

One solution (in addition to my other answer) is to be a bit more explicit in the JSON structure you wish to generate. Basically, here you are providing FOR JSON with some already properly-parsed JSO …
mpag's user avatar
  • 968
0 votes

SQL Server database has corruption, but displays no errors

This certainly is not universally a solution to issues like this, but I was actually running into these errors on 2008R2 as well this last week. Msg 0, Level 11, State 0, Line 0 A severe error occ …
mpag's user avatar
  • 968
5 votes
Accepted

Lead/Lag Implementation in SQL Server 2008 R2: Max memory exceeded

I'm submitting this as an answer, as I am currently avoiding the out-of-memory type errors as well as have reduced the time of run significantly (was 4+ hours, ending in failure; now is 1.25 hrs, endi …
mpag's user avatar
  • 968
7 votes
1 answer
3k views

Lead/Lag Implementation in SQL Server 2008 R2: Max memory exceeded

Background I'm trying to establish a "visits" sequence, wherein if an animal is detected at essentially the same place (General_Location) it counts as a single visit, but if it goes elsewhere and the …
mpag's user avatar
  • 968
3 votes
1 answer
1k views

T-SQL: CSV->table pipeline with custom parsed numeric data, lookup values

Problem Wish to insert thousands of records into a table [Child] from a CSV file (and do this from tens of files into the same table). However, I want to A. substitute a lookup value into the table ( …
mpag's user avatar
  • 968