Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

2
votes
0answers
57 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 ...
0
votes
1answer
30 views

Simple join between 2 tables with unusual structure

I have two tables ACCOUNTS: ...
1
vote
0answers
15 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 ...
2
votes
0answers
22 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 ...
4
votes
0answers
67 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 ...
0
votes
2answers
60 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. ...
0
votes
0answers
19 views

Dynamic “compilation” of SQL stored procedures

I have a stored procedure which is called to create ( "compile" ) temporary stored procedures, code below, based on whether a flag in a database record is set - the various sub-procedures such as ...
0
votes
0answers
25 views

Tracking when a column was last modified using a trigger (in SQL Server)

How can I improve the following code to track when an Azure SQL Database column value was last modified? ...
2
votes
0answers
33 views

SQL Database for Visitor Registration System

This is intended for a web-based application that allows someone to register visitors, assign their hosts, and indicate the dates in which they will be visiting. Imagine this scenario: I want to ...
1
vote
1answer
49 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 ...
2
votes
0answers
28 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 ...
0
votes
1answer
87 views

Modify a column in 2 tables based on trigger

This is SQL Server 2008r2. First, here are some tables and data for test: ...
1
vote
0answers
15 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: <...
0
votes
0answers
120 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 ...
-1
votes
1answer
38 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 ...
0
votes
1answer
34 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 ...
3
votes
1answer
111 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
0answers
19 views

Activity grouping and selection according to order and completion requirements

The problem consists of two categories of events (Work and Rest) which together form a complete set. The number of Work events is open-ended. The number of Rest events is fixed at three (3). The ...
0
votes
1answer
44 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: ...
1
vote
1answer
39 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 ...
1
vote
1answer
121 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 ...
0
votes
1answer
73 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 ...
2
votes
0answers
66 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 ...
2
votes
0answers
60 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: ...
1
vote
0answers
146 views

Stored procedure that adds row-level auditing to a table

I'm looking for any suggestions on how to improve my T-SQL for this procedure. It works okay, but I'd like to get advice to improve it from more experienced SQL developers. This procedure adds 4 ...
1
vote
1answer
74 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 ...
0
votes
1answer
77 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 ...
4
votes
1answer
95 views

Retrieving a product's sold quantity

I've written a view to retrieve each product's sold quantity and four week sales average by Branch/Route/...
2
votes
2answers
102 views

Stored procedure to implement a search filter

I've implemented a stored procedure for a search process SQL Server 2008. I'm not sure if everything I created is correct. Also I'm wondering if this code has any leaks or vulnerability on SQL ...
7
votes
2answers
96 views

Find how much reputation a user had on a given date

I saw this question on MSE and went ahead and wrote a solution to it: https://meta.stackexchange.com/questions/313561/determining-users-reputation-as-of-particular-date This calculates the ...
3
votes
3answers
291 views

Slow SQL Server performance with multiple PreparedStatement loop

I have a need to update thousands of database records at a time. I am using a loop to generate the necessary PreparedStatement updates, but am hoping for a more ...
1
vote
1answer
48 views

Worst Query performance issue on date calculation

I have a stored procedure that is taking more than 2 hours to complete and I noticed the below SQL is taking close to 25 mins for updating a million+ values.There are multiple steps like this and all ...
2
votes
2answers
44 views

Query to find instances of two types of events occurring more than one second apart

I have 3 tables on my database: BusinessObject and CustomEvent, and EventType. ...
4
votes
2answers
33 views

Select recordIDs for Bill of Materials

I have a hierarchy of parts in my database. For example, one part (call it 0010102-0112-315) is a resistor. It's used in a billion different top-level assemblies. ...
3
votes
0answers
73 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
0answers
109 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
39 views

Ledger query using window functions

This is a ledger kind of table, initial amount is when the movement is null and all transactions on it is based on the Waste_Seq the query take the last entry (id) based on the movement and change ...
5
votes
2answers
120 views

Combining SQL Tables into One Table in New DB with Similar Fields

I have a SQL Server Database filled with Reports all having the same schema. What I've done is created a .NET application to automate the process of adding all reports to a new table. How can the ...
1
vote
2answers
125 views

Merge table stored procedure

I wrote a stored procedure that will do a merge of two tables: ...
4
votes
0answers
957 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 ...
3
votes
2answers
81 views

SQL Server - Iterate, aggregate, and insert

I'm trying to find an efficient way to aggregate data for reporting. Let's say I need to aggregate the following data in 5-second intervals: ...
2
votes
1answer
57 views

SQL Query to check if 100+ (or Dynamic) columns in table is null

Let assume a table has more than 100 of columns & I want to display all the rows when all of its columns (Col1, Col2, ..., ColN) are nulls except for the column(s) I mentioned (PK). This is just ...
0
votes
1answer
59 views

Query to show each sites stock transfer history between all other sites

The below query is used to return a dataset for a SSRS report. It works fine and is quick enough but I am looking for any improvements that could be made. The client has asked to see all transfers ...
1
vote
2answers
55 views

Displaying a single record based on DocID

I have a table with ~900,000 records. I need to display a single record based on DocID using this query. The record is the latest record that got modified by another program. This piece of query run ~...
-1
votes
3answers
121 views

SQL query to classify and count logged messages

I have an SQL query that fetches some stats, and those stats are displayed on a dashboard. The dashboard runs this query every 15 seconds to fetch the most up-to-date data. The query is very CPU-...
4
votes
2answers
56 views

Inserting two rows that are almost identical to each other

I'm trying to make test data for an application I'm writing, and some of my test data is very repetitive, involving inserting a row and then inserting another row that is identical except for one ...
-1
votes
2answers
480 views

Insertion of big TXT file into Sql Server

The code posted below reads 500000 lines from a txt file and imports the lines read in a Sql Server 2014 database, the code works correctly but it takes too much time (even 40 minutes), especially ...
0
votes
1answer
54 views

SQL query to return a set of calculated values per site from multiple tables

I have written the below and am seeking any way that I could improve its performance. ...
10
votes
1answer
118 views

The seasoned Zombie sniper: a query to find unanswered questions with specific tags

The query (on SEDE) This query builds upon the previous and includes the suggestions by rofl as well as the now mentioned activity index. ...
11
votes
1answer
91 views

The sniper: a Zombie searcher for specific tags

Sometimes, it's not enough to know what the easy prey is. You also need to know whether you will be able to hunt it down. What good is an almost turned haskell zombie if you cannot read the functional ...