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
0 answers
427 views

Creating SQL Server Database Users Dynamically from User Input

The Application I have an application in testing that runs off of an MS SQL Server database. The app allows users to authenticate using Windows authentication (that is, using the Windows username the ...
Keith Stein's user avatar
5 votes
1 answer
149 views

Excel to SQL server

I am self-taught when it comes to coding. I want to improve, so please give me advice if I have some bad habits or if there is in general a better way of doing this. The idea of this code is to look ...
herrwolken's user avatar
6 votes
2 answers
230 views

NewSequentialId - pure net core 2.2 implementation of sql server function

i'm currently trying to rewrite sql server newSequentialId() function in pure c# that is performing as fast as possible and eats minimum memory. Question is can I it be done better - current ...
DevOnBike's user avatar
2 votes
1 answer
103 views

Reading customer data

This is the first time I am writing R code to access/manipulate and save data. The SQL query I would normally run then save to a spreadsheet, read it into R, save to another sheet then copy and paste ...
MCP_infiltrator's user avatar
2 votes
1 answer
2k 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 ...
Surensiveaya's user avatar
3 votes
2 answers
4k 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 ...
Chris Carter's user avatar
2 votes
0 answers
56 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 ...
Dizzy49's user avatar
  • 201
0 votes
1 answer
78 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. ...
AppDeveloper's user avatar
5 votes
2 answers
730 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, ...
Zephyr's user avatar
  • 217
4 votes
2 answers
188 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 ...
t3chb0t's user avatar
  • 44.3k
7 votes
1 answer
84 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 ...
IEatBagels's user avatar
  • 12.4k
3 votes
1 answer
87 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. ...
h3n's user avatar
  • 133
1 vote
1 answer
29 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 ...
MCP_infiltrator's user avatar
3 votes
1 answer
1k 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 ...
Andy's user avatar
  • 43
3 votes
1 answer
143 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. ...
t3chb0t's user avatar
  • 44.3k
1 vote
1 answer
45 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. ...
J M's user avatar
  • 119
3 votes
1 answer
243 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 ...
Umair Bajwa's user avatar
1 vote
1 answer
1k 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 (...
whytheq's user avatar
  • 497
12 votes
1 answer
287 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. ...
this's user avatar
  • 2,029
2 votes
1 answer
108 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 ...
Mr.J's user avatar
  • 123
1 vote
1 answer
95 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. ...
Pavel Kononenko's user avatar
3 votes
1 answer
43 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 ...
Pavel Kononenko's user avatar
4 votes
1 answer
65 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 ...
bendodge's user avatar
  • 143
4 votes
1 answer
1k 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 ...
JeremyVm's user avatar
  • 143
1 vote
1 answer
70 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 ...
Parvez's user avatar
  • 23
1 vote
1 answer
624 views

Insert multiple rows without using CURSOR SQL Server 2014

I have a fairly complex query which insert multiple rows into a table from multiple tables. Its works fine but I really don't want to use cursor as some blog says cursor took long time for execution (...
Parvez's user avatar
  • 23
1 vote
0 answers
29 views

Log table with a summary of claims

I'm writing a log table which contains the summary of the claims. The log table logs the data whenever there is an upload. I have written the following SQL query. Though it serves the purpose, I'm ...
Ramji R's user avatar
  • 111
2 votes
1 answer
232 views

Web Server handler class to pass IIS http requests to SQL Server stored procedures

This is a c# class I use to implement web database applications with Microsoft IIS and Microsoft SQL server. It passes the http context to a selected SQL stored procedure, and writes a response based ...
George Barwood's user avatar
1 vote
1 answer
244 views

Simple join between 2 tables with unusual structure

I have two tables as below ACCOUNTS: ...
styx's user avatar
  • 201
1 vote
1 answer
87 views

Read comma separated values and insert in SQL Server 2016 table using String_Split

I know that this question has been asked many times over many years and I have read every one of them but I wanted to get a modern solution since software has changed and ...
user1314159's user avatar
3 votes
2 answers
611 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 ...
Matthew Stott's user avatar
1 vote
1 answer
1k 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 ...
Quandary's user avatar
  • 159
7 votes
1 answer
306 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 ...
BCdotWEB's user avatar
  • 11.2k
0 votes
2 answers
83 views

Bash Script for file auditing, push information to server and be able to view in a web page

Edit: The goal of this Question was only seeking code review and guidance in learning or tips for improvement. I apologize if that was not clear or aligned properly with the goals of this forum. ...
Maggie's user avatar
  • 13
1 vote
1 answer
2k views

Upload csv file to sqlserver with python

I have to weekly upload a csv file to sqlserver, and I do the job using python 3. The problem is that it takes too long for the file to be uploaded (around 30 minutes), and the table has 49000 rows ...
Rafael Polara's user avatar
4 votes
1 answer
94 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 ...
Ashish Gupta's user avatar
0 votes
1 answer
106 views

Modify a column in 2 tables based on trigger

This is SQL Server 2008r2. First, here are some tables and data for test: ...
Yuropoor's user avatar
  • 117
1 vote
0 answers
29 views

Calculate BACKLOG_M_1

I need to calculate the BLACKLOG_M value corresponding to the Snapdate of the first of the month. It becomes a constant value repeated for each line of the month As it is explained in the picture: <...
user190108's user avatar
1 vote
0 answers
124 views

Syncing a table to a remote database

I want to sync the table every few minutes to a remote database. I want it to be as efficient as possible. I wrote this stored procedure that will only return rows that are added or removed after the ...
SIRS's user avatar
  • 53
2 votes
1 answer
393 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 ...
VK_217's user avatar
  • 141
0 votes
1 answer
59 views

Quickly check whether file name is in column in an SQL Table and move to new folder

I have a table that in one of the columns exists a list of file names. The names comes from other tables and the files in a folder. Not all the files are used, may be attached to parcels that no ...
Scott Craner's user avatar
3 votes
1 answer
149 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 ...
Mike's user avatar
  • 185
0 votes
1 answer
57 views

Updating 3 columns conditionally on a database table

I need to run this script to update the value of 3 columns based on certain conditions. Right now, this is what I have: ...
João Pinto's user avatar
3 votes
1 answer
81 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 ...
RMSPereira's user avatar
3 votes
1 answer
1k views

Inserting data into SQL-Server table dynamically

I know I can do all this via SSMA quite quickly, but I wanted to see if I could do it efficiently in PowerShell myself as a little project. Basically, the entire script takes tables from an Access ...
Owain Esau's user avatar
1 vote
1 answer
108 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 ...
Jaskier's user avatar
  • 111
2 votes
0 answers
73 views

Insert items from one table that do no exist in the other one [closed]

The insert query below must insert the items not present in the Articolo table by importing them from Importazione, and must update the items in the Articolo with those present in the Importazione. To ...
riki's user avatar
  • 153
2 votes
0 answers
82 views

One class for MySQL and MSSQL Queries

EDIT BELOW I am trying to create resusable classes for MSSQL and MySQL queries (later also Update and Delete queries). I tried it doing the OOP-way. Here is my result: Einstellungen.vb: ...
PRCV1's user avatar
  • 21
1 vote
1 answer
273 views

Calculate NPS in a stored procedure

We collect customer surveys and one of the questions is the dreaded "How likely are you to recommend our service?" question from which we calculate a Net Promoter Score. (I hate this calculation, but ...
FreeMan's user avatar
  • 1,290
0 votes
1 answer
244 views

SQL Query to get parent parts of materials using Recursive CTE

The intent of the query is to filter out certain materials to get to a list that will then be run through a recursive CTE to drill up through the BOM to the 0 level assembly. P_Parts_CTE is filtering ...
jkane's user avatar
  • 11

1
2
3 4 5
12