Microsoft's SQL Server is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. It originated from the Sybase SQL Server codebase, which is why both products use the extension of SQL called Transact-SQL (T-SQL).

learn more… | top users | synonyms (1)

7
votes
1answer
51 views

Deduplicating value pairs between 2 columns

This was asked in the SQL Helpline room: ...
0
votes
3answers
37 views

Counting pending bookings using a subselect

Can this query be improved? Is there a way to eliminate the duplicate function call? ...
4
votes
2answers
49 views

Top Python badged users from NYC

I forked this StackExchange Data Explorer (SEDE) query from another one, and made it a bit more complex. I'm looking for feedback on my style, as well as answers to other questions (see below). ...
0
votes
1answer
33 views

Display the count of field in a view

I have a table that look like this ...
2
votes
1answer
22 views

Reportable Sp_Who2

One of my issues with sp_who2 is that you need to be in the console to run it as it recalls spid twice and most reporting tools throw this as an error. My question is, would using the code below to ...
1
vote
1answer
63 views

Shredding XML into an SQL table

I have a few "given" things: An SQL Server 2012 table with certain structure Data provided as XML with certain structure My code has to shred that XML into a ...
7
votes
2answers
136 views

Replacement for sp_MSforeachdb

Having been informed that sp_MSforeachdb is undocumented and unsupported, I have been working on creating a replacement stored procedure based off the work done ...
0
votes
0answers
20 views

Stored procedure to compare stored procedure result sets

Originally posted as an answer to a SOF question, this is about a generic procedure that allows back-end developers (e.g. SQL developers) to compare the results sets obtained by running two procedures ...
3
votes
1answer
36 views

Loading a database table using a promise chain

I am creating a util module that I'm using to communicate with a MS-SQL database. I want each public method to return a promise. I started with a private function that executes a DB query and returns ...
1
vote
2answers
53 views

Get Word Doc from SQL table, save temp file, edit that file, save new doc in a different table

I have Frankensteined the crap out of this method and just wanted to make sure of two things. I'd like to make sure that this is the best route to take. If it isn't, I would welcome with open arms ...
5
votes
3answers
67 views

Class Module to wrap up classic ADO call to SQL-server

I do a lot of copying excel vba code related to classic ADO from workbook to workbook, so I've decided to add the code to a Class Module in a single utility workbook and then in all other books just ...
3
votes
3answers
274 views

SQL Procedure that will calculate the Last Price paid for a certain Part

I am trying to write an SQL Procedure that will calculate the Last Price paid for a certain Part. ...
6
votes
2answers
106 views

Finding customer searches and graphing their items

One of the reports I am working on requires me to locate searches a customer makes, and graph them in certain manners. I have one query I'm particularly concerned about. This one takes the most ...
5
votes
1answer
45 views

Report for a restaurant showing hourly sales information for a given timespan

I have been tasked with creating a report for a high-volume restaurant that shows hourly sales information for a given timespan. When generating this report for a single day, it's very quick, but when ...
18
votes
1answer
51 views

Cross-posts from Stack Overflow to CR

What this code does it explained in detail in the top portion of the query. I have left out part of the list of language tags as I felt it was just noise. You can see the full collection here. You ...
12
votes
2answers
80 views

Query to count interactions between users

The source data represents interaction between people. Some are internal, others are external. The internals are recorded in the Users table (represented as the ...
8
votes
3answers
131 views

XML splitting query very slow

I have a query to split a delimited string into to multiple columns. The query is extremely slow and takes more than 5 minutes to handle 80444 rows. How can I improve execution time? ...
4
votes
1answer
87 views

4 database queries, multiple loops in loops, slow processing time

The octoberCMS(based on laravel) controller below is what I use to select the lowest price in 4 pricelists in the given daterange. Prices can vary and it's not guaranteed that the more expensive ...
4
votes
1answer
513 views

Deleting millions of rows from a MSSQL server table

This SQL query took 38 minutes to delete just 10K of rows. How can I optimize it? Index already exists for CREATEDATE from ...
5
votes
2answers
73 views

Using UPSERT to maintain word counts for subtitles

I will first explain the context. I want to read serie subtitles contained in .srt files. I have already done the part of extracting the words from the files (and how many times the word appears for a ...
4
votes
3answers
78 views

Central Database class

I have this web site I inherited as part of my job and it has some old code. I'd like to optimize it, but I don't really have the time to do it right, so I'm looking for some "low hanging fruit" to ...
5
votes
0answers
89 views

Executing dynamic SQL programmatically

Usage (all parameters are optional): ...
2
votes
1answer
177 views
2
votes
2answers
33 views

Sql Server: Getting the highest value based on two uniqueidentifiers - possible to avoid union?

I have two riscProfileTypeIds (both of type uniqueidentifier) of which I need the one with the highest sequence number (the ...
3
votes
2answers
61 views

University Database

I am building a database for a hypothetical university. This is my SQL definition, with generated data added for my future use, such as demonstrating queries: ...
2
votes
1answer
133 views

DbGeography search query

I have a situation in which I need to get the closest road to a DbGeography point. This takes 5 - 8 seconds to run in some cases. I have a ...
0
votes
3answers
108 views

CRUD strongly typed data access

I have a data access class: ...
13
votes
1answer
96 views

Example script for teaching DDL and CRUD/DML operations

I have taught some SQL to others before, and I thought of making a script that has these attributes, for the purposes of teaching: Fully functional to run on local DB instance with no fuss Easy to ...
1
vote
1answer
47 views

Optimise MSSQL Connection .NET Helper Library

I recently posted my old .NET MSSQL Wrapper to be code reviewed: .NET MSSQL Wrapper I had some good feedback and based on that, I was able to re-factor it quite a bit and ended up with the following ...
3
votes
1answer
136 views

.NET MSSQL Wrapper

Back in late 2012, I wrote the following C# .NET MSSQL Wrapper, which offered the following operations: ExecuteScalar (for selecting single field from a row) ...
2
votes
1answer
62 views

T-SQL Constant Time Comparison

Explanation is in the function. Please point out any egregious errors: ...
1
vote
0answers
17 views

T-SQL Totp (Rfc6238 SHA2_256) Implementation

Using my previous function as a base I've come up the following: ...
3
votes
1answer
45 views

Returning two dates based on input

I created a function that will return 2 dates that depend on an input parameter. When the parameter is: 1 - return start date of current week and end date of current week 2 - return start date of ...
4
votes
2answers
47 views

Basic Bill of Materials schema

I've been working on Bill of Materials mini schema for a while. At first I had single Part table where I've referenced itself. I was told it would be better to have ...
16
votes
2answers
1k views

Searching for bad Minecraft questions on Gaming.SE

To preface this post a little bit, I'll explain a little bit of the "backstory" here. The Stack Exchange site, Gaming.SE, also known as Arqade, often has a large influx of bad questions about the ...
1
vote
1answer
39 views

Managing employee photos in a database

I'm looking for a better way to manage employee photos for employee records in our database, and a way to query for the employee photos while having them on disk I have used a ...
3
votes
0answers
37 views

T-SQL Pbdfk2 (Rfc2898 SHA2_256) Implementation

Using my previous function as a base I've come up the following: ...
1
vote
3answers
133 views

Checking user access to servers

I have pasted a method I wrote, which is too slow to my liking (easily takes 60+ seconds to execute). The method loops through 12 different servers, checks if userX has access to any of the databases ...
4
votes
0answers
81 views

T-SQL Hmac (Rfc2104 SHA2_256) Implementation

I'm trying to implement an Hmac in T-SQL using this question as an guide. Please critique this: ...
2
votes
1answer
27 views

MSSQL query with join and where clause

I've the following tables ...
2
votes
1answer
29 views

Find foreign key membership including owner in SQL Server

Was hoping someone could sanity-check this SQL statement. I need to find the owner (schema), table, and column on both sides of a foreign key: ...
1
vote
1answer
34 views

Acquiring the number of contracts for persons

This script shows the number of contracts for persons. Table Contract has more than 82008 records and Candidate has about 7978. ...
4
votes
1answer
103 views

SQL Permission Handling in WinForms

For my application, I've opted to use Integrated Security with Windows Authentication to access the SQL database. I've created AD security groups for each role and given them ...
2
votes
2answers
43 views

SQL query to select most recent version

I have the following table definition: ...
6
votes
1answer
34 views

Finding closest points without duplicates and given distance threshold

Given a bunch of latitudes and longitudes stored as Points, I would like to determine the points that are closest to each point given some maximum threshold in meters. This is my first stab at this: ...
1
vote
0answers
36 views

SQL Query Count Records and Pull Distinct

So I need a little help. It is currently working but I might have over complicated it. So maybe someone has a better idea. Now let me try and explain it. I am trying this query, and it currently ...
1
vote
1answer
42 views

Query performance of this Select Where each Column is a Select

I would like to know how to improve the performance of the following query: ...
1
vote
0answers
93 views

Updating datetime fields from UTC to local time zone

I have created an SQL query to update datetime fields from UTC to local time zone. Can someone review this? ...
2
votes
0answers
30 views

Annualized Turnover Report

What can be made better? How ugly is my code? If it's terrible, where can I improve? ...
0
votes
2answers
137 views

Optimizing LINQ routines

I run a build system. Datawise the simplified description would be that I have Configurations and each config has 0..n Builds. Now builds produce artifacts and some of these are stored on server. ...