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)

-4
votes
0answers
24 views
0
votes
1answer
12 views

Generate SQL for translated resources from Excel Spreadsheet

I do some work that involves translating resources for a webpage. These are all stored in a SQL Server table that looks like this (plus a few irrelevant constraints). ...
3
votes
1answer
69 views

Entity Framework query optimization

A user can track a show, and mark episodes and seasons of that show as watched. To support this I have the models below: Models ...
0
votes
0answers
39 views

SQL BulkCopy - XML to SQL

The application we've built occasionally needs to load XML data into a SQL database. The code works well until the files reach 600kb or greater at which point out-of-memory exceptions occur. The ...
3
votes
0answers
55 views

Query for a ticket system involving cases and casts on many attributes

I have this SELECT statement that inserts into a temp table and it is slow! Right now it takes ~1500 ms to run and only deals with ~7000 rows. As the data grows ...
7
votes
2answers
45 views

Retrieve high views per day questions with few answers

I've been messing around with the SE Data Explorer and I've come up with a query that basically returns information about questions that have a high number of views per day, that have few or no ...
-1
votes
2answers
101 views

Calculating price with a sub query

So I have this sub query: *(select p.value1 From Params as p where p.PAR_Field = 'Taxe' and p.PAR_KEY = 'TVA')* And I was using it 3 times to get the same value. ...
2
votes
1answer
24 views

Stored procedure to swap account holders

I'm doing an exercise, and would like to know if what I'm doing is correct and follows the correct structure for rollback in case a transaction fails. I would like to know as well if my ...
3
votes
1answer
38 views

Database design for users' postcards

I would like to a review of my database design. There are 3 tables + ASP.NET Identity tables. The Users could have many postcards. Here's my tables without Identity. I attached also my scripts ...
1
vote
0answers
56 views

SqlCommand filter by dates are slow

I have these codes(.net framework 2.0): ...
0
votes
1answer
35 views

Repair orders query in SQL Server with subselects

I was wondering if you guys know how to reduce the amount of subselects in this SQL Server Query? I think I'm using bad practices in this: ...
7
votes
2answers
77 views

Database credentials and connector including encryption

I'm designing a small Java desktop application to interact with my database and this is a very important part of it as a majority of the operations will be involving the SQL Server 2012 database. I am ...
4
votes
0answers
60 views

Stored procedure to insert a new person

I have not written very many stored procedures before, and this is the first one I have written to be used in a real business application to write new data into the database, so I would like to get ...
8
votes
0answers
37 views

Flexible Chutes & Ladders using SQL stored procedure

I thought this would be a fun exercise to use SQL to participate in the June 2016 Community Challenge, so I did. Yes, you may call me crazy! I had to write a few little things to help me, I needed a ...
3
votes
2answers
43 views

Finding maxDate for each entity

I have a table with (CompanyNumber, File_Date, [various financial results]) I wanted to get only the most recent set of accounts for each company. After various ...
4
votes
2answers
46 views

Adding dynamic column names to a table

I'm using Microsoft SQL Server 2014 Express. I found myself wanting to add the Columns CompanyNameChangeDate (1 through 10) and ...
4
votes
3answers
53 views

Data import “upsert” from a SSIS package

I have the following "upsert" trigger in SQL Server 2005, which is handling a large data import from a SSIS package. It is taking a very long time to complete - I suspect due to the concatenation and ...
1
vote
1answer
43 views

Demographics information for EDI report

I am going through some of my companies EDI reports to see if I can make them faster. The query below runs in less than one second in our AWS RDS environment, but it takes ~55 seconds on a blade in ...
1
vote
0answers
39 views

SQL query with nested subqueries

The following query is taking over 800ms to run, and returning 300 rows. ...
2
votes
1answer
35 views

Query column names and then using them in statements

I currently have a table with over 250 columns, in which ~10-15 columns have column names that have a specific prefix, namely EQP_. Assume that you do not want to ...
2
votes
2answers
90 views

Copy Data from Informix to SQL Server

The following method copies data from Informix db to SQL Server db and it's so slow, I want to refactor it so it could be more readable and faster: ...
1
vote
0answers
25 views

Exclusive row lock

I'm in a situation where I need to manage a kind of FIFO process within a SQL procedure. The procedure is called by a multithreaded windows application. I've created a table which look like this: <...
1
vote
0answers
46 views

Current .NET session username injection in SQL Server stored procedures

I have a legacy WCF service that is ported from a security model using database logins and roles to a custom security. One effect of this change is that stored procedure are no longer executed using ...
1
vote
1answer
65 views

Finding all delivery orders with multiple purchase orders

I have a SQL query to find all delivery orders with multiple purchase orders (one-to-many). Is there a better or shorter way to write this? ...
0
votes
1answer
38 views

Convert MS SQL datetime to Oracle varchar(32) interval

I have a query against an MS SQL database that takes the resulting dataset and stores it in an Oracle database table which then gets joined to another Oracle table using the column ...
2
votes
0answers
19 views

Generating days in a specific range

I have a query in MSSQL, where I get a summary by days from a range in a table, and this is in union with other queries. This query is used to generate days in a specific range, then add the registry ...
2
votes
2answers
213 views

Update user country based on IPv4 decimal address

I have UserSignatures, a table with clientIPs, some of which have CountryIds that are null ...
0
votes
2answers
47 views

Get parent folder ids by folder id(s)

My Scenario: #TmpDistinctFolderIds table contains one or many FolderId. ...
2
votes
2answers
69 views

TSQL query to gather amounts for an employees, spouses, and children in one row

I have a query that works as intended, kind of pulling from multiple records in a table, and flattening the data into one row. I am wondering if there is a faster/more semantically correct way to do ...
1
vote
1answer
246 views

Python Pandas Apply with a Lambda Function

I have a table in pandas that has two columns, QuarterHourDimID and StartDateDimID ; these columns give me an ID for each date / ...
1
vote
2answers
58 views

Pivot script for sales numbers

I've recently been tasked with migrating some code stacks for an applicatin that is moving from using Access to using SQL-Server. I don't usually use PIVOT all ...
4
votes
1answer
65 views

SQL procedure for Archiving and Deleting

I have a requirement for archiving 5 huge tables from PROD to ARCHIVE server without losing the integrity of the tables. The query makes use of the Linked Server functionality and current idea is to ...
3
votes
1answer
72 views

Database trigger to monitor insert/update events and update another table

I am working on a MSSQL Database (for a program called Sage 200). There are many tables in the database, however, I want to be notified of changes (new record inserted or existing record updated) via ...
2
votes
0answers
41 views

T-SQL Secure String Comparison

The previous version of my function was scalar-valued and employed a WHILE loop to do the comparison, this is SLOW. This new version is tabled-valued and uses a typical tally table in place of the ...
1
vote
0answers
24 views

Stored Procedure enhancement for updating columns in a subset

The purpose of this store procedure is to reach into a large database (test), query for a subset, and update a column value, but with a big constraint - I can only update one row at a time. The ...
1
vote
1answer
23 views

Get top row for muliple registers

I came across a piece of code that generates SELECT queries from a template. The template: ...
0
votes
0answers
38 views

Validating an NPI in T-SQL (Luhn's Algorithm)

The requirements for validating a national provider identifier can be found here. Here's my attempt at a T-SQL implementation: ...
1
vote
0answers
102 views

WCF service architecture when SQL Server direct table access is not allowed

Part of my job is to maintain an old application written in Silverlight talking to a WCF service which in turn fetch/persist data into a SQL Server database and in a BI cube. Most of the security is ...
3
votes
1answer
62 views

Stored procedure to query custom data tables as dynamic SQL

There's a lot going on here, but the background for why this is necessary is that there is a set schema, or 'core' set of tables that are prefixed with 'bu', and any core table can have a custom table ...
0
votes
1answer
26 views

Finding colors that have not been assigned to a given user

Goal: make this code as efficient as possible. Given a finite dataset (Colors - this isn't Crayola here :D) how do I know what colors are not assigned to a given user? Additional requirement - the ...
-2
votes
1answer
64 views

Sample SQL Server code using pivot table

I'm using a dynamic pivot example. This SQL code has the purpose of perform transposing data from rows to columns, using a temporary table in SQL Server. The data is initially presented this way: <...
3
votes
1answer
80 views

MSSQL query to look for duplicate record

This query took 6 seconds to complete. How can I optimize it? Total records in table is 166803. ...
3
votes
2answers
130 views

Insert or update user data

I inherited an application that uses some stored procedures. Here is a sample of one of the stored procedures used to insert or modify user data. would like to get the group's opinion on the code. ...
1
vote
2answers
90 views

Powershell script to iterate through folder and restore SQL backups

I am working on a PowerShell script which will loop through a directory containing SQL Server database backup .bak files; move the files to a different location; restore each of those files to the ...
4
votes
1answer
62 views

Stored procedure to classify policies by sales date

Currently this is the store procedure I am working on, it is working according to some testing that was done. I feel that it could be improved though, could use some optimization, feedback or ...
6
votes
2answers
76 views

Deduplicating value pairs between 2 columns

This was asked in the SQL Helpline room: ...
0
votes
3answers
44 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
61 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
35 views

Display the count of field in a view

I have a table that look like this ...
2
votes
1answer
31 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 ...