Skip to main content

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
4 votes
1 answer
139 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/...
Shelby115's user avatar
  • 1,961
2 votes
2 answers
2k 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 ...
Milos's user avatar
  • 21
6 votes
2 answers
119 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 ...
Magisch's user avatar
  • 330
2 votes
2 answers
1k 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 ...
Zephyr's user avatar
  • 217
2 votes
2 answers
99 views

Replacing birth year column values with calculated age value

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 ...
VK_217's user avatar
  • 141
2 votes
2 answers
56 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. ...
Thomas Ayoub's user avatar
4 votes
2 answers
49 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. ...
Cullub's user avatar
  • 185
3 votes
1 answer
387 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 ...
jDave1984's user avatar
  • 208
7 votes
0 answers
155 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 ...
Guillermo Subiran's user avatar
1 vote
1 answer
54 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 ...
Fredou's user avatar
  • 385
5 votes
2 answers
144 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 ...
William Humphries's user avatar
0 votes
2 answers
4k views

Merge table stored procedure

I wrote a stored procedure that will do a merge of two tables: ...
soandos's user avatar
  • 163
6 votes
1 answer
5k 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 ...
A_V's user avatar
  • 183
3 votes
2 answers
98 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: ...
Jake Reece's user avatar
2 votes
1 answer
109 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 ...
DxTx's user avatar
  • 123
0 votes
1 answer
81 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 ...
NinjaArekku's user avatar
1 vote
2 answers
61 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 ~...
SIRS's user avatar
  • 143
0 votes
3 answers
205 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-...
user avatar
4 votes
2 answers
63 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 ...
Troy Nguyen's user avatar
0 votes
2 answers
2k 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 ...
riki's user avatar
  • 153
0 votes
1 answer
62 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. ...
NinjaArekku's user avatar
9 votes
1 answer
132 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. ...
Zeta's user avatar
  • 19.3k
11 votes
1 answer
112 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 ...
Zeta's user avatar
  • 19.3k
15 votes
1 answer
1k views

A wounded Zombie finder, or: how to find the almost dead undead?

The Zombies are on their way to eat our statistics. Fortunately, we have a way to get rid of them: our votes. However, we need to find them first. The /unanswered section is too large and contains ...
Zeta's user avatar
  • 19.3k
3 votes
1 answer
2k views

Implementing RecordSet-like class in C#

From the outset, let me state that I'm working with some older technology. I'd rather use Entity Framework, but I have to use what the client is using if I want to get paid. I am converting some old ...
Jonathan Wood's user avatar
1 vote
1 answer
365 views

Query result as an HTML table

I am not a expert on php html. I built a website 2 months ago, and realized I using lot of php query result on web. Is there any approach without while my query result on multiple times ...
Munkhdelger Tumenbayar's user avatar
0 votes
2 answers
77 views

CTE Query and DateTime Matching

I have two tables (they are defined below and you can use the SQL below to build them) ...
MoonKnight's user avatar
0 votes
1 answer
1k views

T-SQL query outer apply with nested subqueries

I have the following 3 tables, and I don't have the option to modify them. [Logs] table with [log_type], ...
Thomas Hsieh's user avatar
3 votes
2 answers
4k views

Retrieving data from SQL DB based on user input

I wrote this to connect to a local DB using my local login credentials. It pulls back card information based on the user's input. ...
Das Nuk's user avatar
  • 33
1 vote
1 answer
79 views

SQL report of hazards for selected processes

I've written some code in VBA to help our R&D department. I've moved all of the redundant and static information into a database for them to look up and then generate a report from. I've ...
jDave1984's user avatar
  • 208
3 votes
1 answer
375 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: ...
pawelty's user avatar
  • 131
5 votes
1 answer
228 views

App for providing accounting solutions for clients

I have a VB6 app that has existed for more than 7 years to which I have a few clients using it for their accounting solutions. Now my problem is that a particular client has grown so big with a 15GB ...
Tobyy Damian's user avatar
2 votes
2 answers
144 views

T-SQL simplify repeated query unions for each day of the week

I've created the T-SQL code below to get the next nearest datetime value during the next 7 days. The ScheduleDetail table schema is: ...
qwertydog's user avatar
1 vote
1 answer
116 views

Update Trigger (Comparing Descriptive string), as well as checking for valid updates

I have an audit table EpisodesHistory. One of the fields that gets copied is eDescription. I expect ...
Regular Jo's user avatar
1 vote
1 answer
971 views

Ontario Health Card mod 10 validation

An example of the business rules are here. Does this code implement those rules correctly? Note that you will have to derive the rules from the example. ...
Dan Bracuk's user avatar
0 votes
1 answer
43 views

Selecting data from a table based on value in another table (SQL server)

I am using the northwind example database to brush up my SQL server skills. I want to select all the products ordered by the customer with the customer id 'Folko'. My idea is to join the Orders ...
karra's user avatar
  • 111
1 vote
1 answer
70 views

Simulating a hospital

I have a Java program which simulates a hospital. For this, I have two different databases, MySql and MS SQL, with tables to manage the patients. The user can decide which database he wants to use. ...
Dominik Wolf's user avatar
0 votes
2 answers
245 views

SQL Server Multi Term Wildcard Search on Multiple Fields with Ranking

I've built up this search query for searching airport locations on multiple fields, but I don't particularly like the way it works in practice. Even though it is fairly cool. I'll be reverting back to ...
James Law's user avatar
  • 497
3 votes
1 answer
56 views

Comparing columns values and change their places by condition

There are three simple tables. Actor, Film, Film_actor. ...
Learner's user avatar
  • 143
1 vote
1 answer
170 views

Report which connects to SQL Server via ODBC

I've created a report in Excel which connects to SQL Server via ODBC and I wrote some VBA to allow parameters to be passed in optionally. At this point everything works as expected but I'm curious to ...
Jonathan Porter's user avatar
3 votes
1 answer
99 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 ...
indigochild's user avatar
4 votes
1 answer
778 views

Multilingual website with a database

I created a multilingual site in MVC and I reached the current results, but I'm not sure it's the right way. I have created a class named changeLanguage to change ...
Elxan's user avatar
  • 53
1 vote
2 answers
66 views

Stored procedure for processed orders in SQL Server

I am struggling with creating a Stored Procedure in SQL Server for getting sales statistics. I have managed to get the information I need out, but the query is a mess and I have probably messed up the ...
thrustmaster's user avatar
0 votes
1 answer
93 views

Looping in SQL Server to insert row into table at top

Here I have a stored procedure that seems to be taking a little longer to run than I had hoped for. What made this algorithm so lengthy was the fact when adding an element to a new table in SQL it ...
SQLUser's user avatar
2 votes
2 answers
3k views

SqlCommand ExecuteReaderAsync helper method

The following helper method executes commands asynchronously and returns a Task<IEnumerable<T>> where T is a type that receives the row information from ...
Cleve's user avatar
  • 121
2 votes
1 answer
852 views

Duplicate Payments using SQL

Working on identifying duplicate vendor payments using SQL in MS Access. The business logic uses four column; Vendor #, Invoice #, Invoice Date and Invoice Amount. There are 5 core reviews, if all are ...
Caleb Ford's user avatar
4 votes
2 answers
380 views

Connection String Decorating

I found myself in a situation where it is necessary to often decorate connection strings with some kind of metadata, like an extra DB Provider attribute, read it back, and remove the decoration ...
Dmitry Nogin's user avatar
  • 6,131
1 vote
1 answer
972 views

EF Core Complex Query Method

The code is returning reviews based on users like status order. It seems it executes a lot of SQL queries, so do you think it can be simplified and can it be a headache to server performance? ...
Okan Aslankan's user avatar
1 vote
2 answers
55 views

Getting data from two tables

This query gets data, but for 116819 rows I need to wait 2:19 minutes. Getting the same data from the table takes 2-3 seconds, but I need some rows from the view (that are matching my data from table) ...
leopcode's user avatar
3 votes
1 answer
8k views

Converting local currencies into one target currency using the exchange rate table

The solution is to be used on MS-SQL server. The presented code was tested on MS-SQL 2012. I was given the exchange_rate table that reflects the human interface (...
pepr's user avatar
  • 283

1 2
3
4 5
12