Questions tagged [sql-server]

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).

Filter by
Sorted by
Tagged with
3
votes
0answers
25 views

Database Model for Feedback Module

I wish to generate an online feedback system. Requirements are Admin can enter feedback questions Admin will select these questions and create a feedback session One Question can be used in many ...
0
votes
0answers
63 views

Cancel Long Running Query using Cancellation Token AND SqlCommand.Cancel()

I need to be able to cancel a long running query programmatically through our application. The code below will kick off a long running query and give control back to the main thread. At any ...
3
votes
1answer
60 views

Calculating all flight connections

I am working on an API to return all the possible flight route between point A and B. I have a set of data which includes the flight number, airline, departure airport, destination airport, departure ...
2
votes
1answer
50 views

Determining daylight-saving time in Central European Time

(We are on SQL Server 2008). The following constellation: Our applications passes date&time around (in the most horrible way possible). We want to simplify this. Instead of a culture-specific ...
3
votes
1answer
100 views

Generating email with BCP

This code iterates through the table @Table1 to get the Purchaser, PurchaserID, ...
2
votes
0answers
39 views

SQL Code That Looks for Dupes with Confidence Score, 3hr / 1.2 BILLION Rows Returned. Optimize?

OK, I have a customer list that has approx 80k records. I need to search and compare looking for duplicates, but duplicates could be an exact match, or a similar match (only some data matches) so it ...
1
vote
0answers
23 views

Searching for Duplicates in SQL Table with Confidence Score

Sometimes I'm not sure if my questions should be here or StackOverflow, so I appologize if this is the wrong place. I have a SQL (MS SQL 2016) stored procedure that is evaluating data looking for ...
0
votes
1answer
70 views

database connection, fetching rows and handling error in csharp

Fetching database records and displaying as JSON. Asking for revision to ensure if everything's ok, i.e. connections are properly handled and closed in case of error. ...
0
votes
0answers
21 views

SQL Server - Flagging overlapping time entries and calculating time without overlaps

Here's my example set up in rextester. https://rextester.com/LROA87361 I have the following table in gray (the rightmost 2 columns are for explanation). As you can see an employee's time entries ...
2
votes
1answer
239 views
3
votes
1answer
76 views

Creating SQL Indexes on Large Tables

I currently have a table with about 29 million records. The table currently has no indexes. However, I would like to build a clustered composite index built on three columns. When I attempt to add ...
2
votes
1answer
59 views

Validating region/state/province codes for different countries

I have a large table in which I store region/state/province codes (two letters) from different countries. I use these region codes further downstream for multiple process. One of the steps I do is a ...
6
votes
1answer
105 views

Retrieving the IDs of entries to be deleted from a table

Business logic It would take us too far to explain the whole business case behind this code, so I'll try to be as succinct as possible. There are Persons, and ...
7
votes
2answers
483 views

Dynamically re-index all indexes in all databases on server

The intent of this SQL Server query is to: Dynamically work rebuild/reorganize all indexes in all tables in all databases on a server. Rebuild or reorganize depending on the specified fragmentation ...
6
votes
1answer
64 views

Zombie killers ranking

Code Review has a Zombie Problem and, in comparison to The Walking Dead TV Show, our survival doesn't depend on killing them all day every day. As a potential solution, I though it would be ...
5
votes
2answers
73 views

Query with multiple foreign keys to the same table

I have a primary table, REP_ASSIST.ES_LOG with multiple columns that are foreign keys to another table, ...
4
votes
1answer
94 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 ...
3
votes
1answer
200 views

Matching entities in SQL Server to replace iterative Python script

I have a SQL (MS SQL Server) database of ~22 million companies (called target_db in my code). For example: ...
4
votes
2answers
58 views

Acquiring earnings information

The first part of the query grabs Policy's Premiums, Effective and ...
5
votes
1answer
39 views

SQL Trigger - Audting Config Table - Send Email with update details

Keep in mind i'm not an expert or developer, working in IT operations and improving my coding skills. Goal: Trigger to send email when a specific configuration table is updated or deleted. Should ...
6
votes
1answer
67 views

Stored procedure to describe the reason that a particular employee is unsuitable for a particular task

I used the following Stack Overflow questions as references for writing this code: Select columns from result set of stored procedure What is the equivalent of String.Join on TSQL? The idea behind ...
3
votes
1answer
123 views

Reading Database, scraping Barchart and uploading prices to DB

This is my first real excursion into Python, coming from C#. I wanted to see if my code is well-formatted and efficient. The following will read the needed codes from a Database Table, then submit ...
6
votes
1answer
2k views

Fastest way to insert rows in mysql vs sqlserver (large dataset)

I'm looking for any possible improvements that could be made to run the mysql piece of code faster. I created a simple test winform application that creates two docker databases : Sqlserver on linux ...
22
votes
3answers
322 views

“How can I make this SEDE query better?” (bad title finder)

It was suggested on Meta for July 2015 Community Challenge to make a bot that can find questions with bad titles. I wrote this query to help others find examples to help them make write their code. ...
2
votes
1answer
79 views

My first c# program: Get Data from Sql Server and show it in Textboxes

So I have been programming in VB.net and want to learn C#. I "successfully" created a simple program that retrieves data from Sql Server during Form1_Load. The ...
5
votes
1answer
127 views

T-SQL Pbdfk2 (Rfc2898 SHA2_256) Implementation

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

Safe dynamic SQL for generic search

Prompted by discussion about SQL injection, I wanted to put a proof of concept forward to get feedback about whether this is in fact safe and protected against SQL injection or other malicious use. ...
3
votes
2answers
153 views

Function to get current value or default from a string of two values

I have SQL scripts that I want to be executable directly in the editor (like DataGrip or SSMS) and also in automated integration tests. However, in each use-case they require different environment and ...
3
votes
1answer
55 views

SQL Sub-query with running total optimization

The codes below get the rows of data until it reaches the total running quantity limit. Notice that the SQL uses sub-query. ...
3
votes
1answer
77 views

Deleting millions of logs in batches

I have a fast growing table with logs that I frequently have to delete (the server doesn't have much resources). It grows by at least two million entries every day. The database is a SQL Server 2012. ...
3
votes
1answer
62 views

Daily SQL job to delete records older than 24 hours

Below is a delete job to delete 1M+ records daily and takes 13 hours to complete and sometimes more than that. I need to optimize this. The table tblcalldatastore is being inserted 24*7 through a ...
3
votes
1answer
51 views

Loop Through bitarray to retrieve subsets of that bitarray

Objective: I want to loop through a bitarray and store subsets of that bitarray in a table. Context: I have a bitarray with 48 elements where each element represent one hour. I want to look back 24 ...
7
votes
0answers
137 views

Modeling tabular structure in MSSQL to store data like Excel sheet applying Column inheritance

I've created this database structure to store tabular information (it's a simplification of my real structure but enough to show the point). In it I have Sheets and ...
1
vote
1answer
21 views

T-SQL Getting Sequential events with first even criteria

I have a query I am writing where I want output if a person has some service provided, then I want all the services they had provided after that and I don't want the individual returned if that is the ...
14
votes
1answer
9k views

Conditional Create: must be the only statement in the batch

I only want to create this SQL function if the dependent Assembly exists. I can do it using dynamic SQL, but it seems messy and I lose syntax checking (in management studio). This function's ...
4
votes
1answer
43 views

Get local datetime from UTC time

One of the app is inserting date in UTC format (column CreateDate). When reporting from this table, I used a difference in hours between the inbuilt ...
3
votes
1answer
32 views

T-SQL Query remove duplicates except for original row from the table

Question: There is an Exam_Merge table into which to import records from a similarly structured table in another database. In this case, the Exam_Merge table contains the values of the primary key ID ...
1
vote
1answer
33 views

Updating field in Temporary table

I have a more massive sp, in which I use some temporary tables, below is a part of the sp where I am updating a field in a temporary table two times. ...
3
votes
3answers
14k views

Search using stored procedure

I want to search a DB table and display the records in a gridview below is my stored proc ...
1
vote
1answer
78 views

T-SQL query Choose name of clients, concluded more than one loan agreement in 2010

QUESTION: Choose the name of clients, concluded more than one loan agreement in 2010, as the numbers and dates of issue of these contracts. Sort by name of the client and date of issue of the loan. ...
1
vote
1answer
92 views

SQL Stored Procedure to export specified data

I'm currently using a stored procedure(sproc) to export to Excel. The sproc is being passed ...
3
votes
1answer
133 views

SQL SP creating certificates for shipping

We ship large spools of copper wire and pallets of copper rod that have to meet specific chemical and mechanical requirements, this is what must be put on the certifications. I created an SP which ...
1
vote
1answer
167 views

Do these BLL-DAL comply with the Dependency-Inversion Principle and is this valid Dependency Injection?

I am working on a very simplified proof of concept (POC). Separation of concerns should be achieved in this project, so that in the future we have flexibility in respect of what data source we use (...
0
votes
1answer
95 views

Modify a column in 2 tables based on trigger

This is SQL Server 2008r2. First, here are some tables and data for test: ...
2
votes
0answers
485 views

Generic polling class and using it to poll SqlConnection

I have the following poller class that can be used to "poll the required action": ...
0
votes
0answers
47 views

Parties and Messages in SQL e-Commerce db design

I'm posting a follow-up question based on my first question. My goal is to, as an exercise for myself, create a complex (in my opinion) e-commerce application. The explanation of the application can ...
4
votes
1answer
223 views

SQL e-commerce database design

I want as an exercise to create an e-commerce application from bottom up. My main goal here is to gain a lot of knowledge. I have experience in web development, but never have been there from the ...
4
votes
1answer
40 views

JSON from SQL Server: Reduce lists of single dicts to list of values

SQL Server 2016 introduced some JSON features, but they're far from robust. As far as I can tell, there's no way yet to output a simple array; everything must be in ...
3
votes
2answers
103 views

SQL Query - records within the last year

Bit of a complicated one for me. I have a database full of hundreds of thousands of records, many of which are duplicated. I need to get all records within the last year but making sure every ...
1
vote
1answer
54 views

Query to generate payroll based on attendance for a month

I have written a query to generate payroll based on attendance for a month, for about 4000 employees. It takes quite a long time to execute. Basically, what I am doing is to joining two different ...