Questions tagged [stored-procedure]
A stored procedure is a subroutine available to applications that access a relational database system. Typical use for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures can consolidate and centralize logic that was originally implemented in applications.
78
questions
2
votes
1answer
34 views
Performance stored procedure update multi-coulmn sql
I have a stored procedure the every 5 min run in sqlserver
high cost iO/cpu
do you have any idea to tune this query
...
1
vote
1answer
42 views
MSSQL database structure and stored procedure performance
I build database called MessageBoard and created StoredProcedure GetHomeView that return data for HomeView. I am completely new ...
1
vote
0answers
32 views
Stored procs fine tuning for processing bulk data - 5 million records
I have this procedure which is used for bulk upload data from a temporary table (temp_rules_master) into two other related tables.
It has 5 million records. The ...
1
vote
1answer
65 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
32 views
Insert data from one table to another (million+ rows)
I have a procedure that collects data from one table and inserts it into another table with the same columns, but after correlating with a few other tables. Since the existing table (from which data ...
4
votes
1answer
498 views
MySQL JSON diff procedure
I'm building a procedure which compares two JSON objects and return two JSON objects with differences between each (compared keys and values).
But I have relatively superficial SQL knowledge, so I ...
3
votes
1answer
144 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
95 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 ...
1
vote
0answers
174 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
154 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 ...
2
votes
2answers
1k 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 ...
3
votes
1answer
38 views
Stored procedure for sending emails at specified times after license expiration
I need to send email notifications for expired licenses:
One Day Before/After Expiration
Two Days Before/After Expiration
Three Days Before/After Expiration
One Week Before/After Expiration
Two Weeks ...
0
votes
1answer
57 views
Filtering query by date built from integers
I am trying to make a stored procedure and pass some parameters for filtering. As soon as filtering is in horizon, code has to be as generic as possible with as few as possible ...
11
votes
1answer
259 views
Science Fiction Wall of Fame (Shame?)
I have a few of hobbies, one is reading science fiction and fantasy and another is coding solutions. I thought I might have a chance to combine both hobbies on this project.
I have well over 1500 ...
2
votes
1answer
42 views
Inner Join only if satisfies If condition
I'm looking for code review, and optimizations.
I have two tables ItemCategory and ShopItemCategory
ItemCategory
...
6
votes
1answer
671 views
Univariate analysis with SQL stored procedure
I wrote a SQL univariate analysis stored procedure taking as input a schemaname and a tablename on PostgreSQL. It is exactly like a PROC SAS UNIVARIATE. As output, you get less than 20 usable ...
1
vote
2answers
57 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 ...
1
vote
0answers
118 views
Insert complex object into multiple sql server tables
I am inserting data into three tables Properties, Rooms and RoomImages, using a stored ...
1
vote
0answers
889 views
Mysql Stored Procedure: group_concat with group by, and then all combinations of elements in csv
Problem
So what problem am I trying to solve?
Given that we have a list of IDstrings, with an associated region, I want to produce all the different combinations of IDStrings possible for a specific ...
1
vote
2answers
5k views
Fetch data from database either with a stored procedure or a query
I have this method, GetDataAsync(), that grabs data from the database using a stored procedure if sqlToRun Dictionary contains ...
2
votes
2answers
92 views
SQL Server Stored Procedure quality
I'm beginner in programming and I have recently written quite an advanced stored procedure. Based on parameters with which I call it, it returns data and groups it, but that is not the most important ...
3
votes
1answer
29 views
Creating a join table entry by looking up name
I wrote a stored procedure that allows a join entity to be created by name for my fictional characters database. I would like some feedback on it with regard to exception handling, and conditions I ...
6
votes
1answer
68 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 ...
5
votes
2answers
613 views
Locking in MySQL stored procedure for deduplication
Multiple upstream servers are sending notifications to a load-balanced django app. If all the upstream servers are working correctly, the app will always receive duplicates of these notifications (...
2
votes
1answer
157 views
Second-sealed-bid auction web app
I am working on a second-sealed-bid auction web app. I have an Auction table to keep auction items on record, a Bid table to ...
2
votes
1answer
78 views
Working out statistics for unique users
The below code is run on a routine rather than say login time but being new to using FETCH NEXT I can't help think maybe there is a trick here to merge at least one of the SET lines.
The end results ...
1
vote
1answer
96 views
Stored procedure for product search with dynamic filters
Below stored procedure implemented for filtering and sorting operation.But number of table column increases below query becomes complex to read/maintain. This is good for small tables.
I want to ...
5
votes
1answer
40 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 ...
2
votes
2answers
609 views
Optimize store proc performance being called in c# on array loop
I have a c# application(mvc) that allows a user to upload an excel sheet containing an account number key and amount value to be passed as parameters to a proc that then validates those records, the ...
1
vote
0answers
930 views
Interface for Dapper repository
I'm creating a little proposal for the data access layer using Dapper ORM.
The code is based in an generic interface IStore:
...
3
votes
1answer
268 views
Get all company branches using stored procedure
Am creating an application for a transportation company that will store information about their drivers, the cars they drive and to what branches and districts they belong to.
I have a branch table ...
2
votes
1answer
42 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 ...
6
votes
1answer
181 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 ...
1
vote
0answers
68 views
MySQL stored procedure to search medical insurance claims
This stored procedure is taking a lot of time to execute. How can I optimize this query?
...
3
votes
2answers
87 views
Fetching a number of data tables from a stored procedure
Within a method, this code is calling a SPROC that is doing a 'select *' from 9 different views. This method then goes on to access the returned DataTableCollection ...
1
vote
0answers
520 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 ...
4
votes
1answer
120 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 ...
5
votes
1answer
2k 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
1answer
69 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 in order to ...
3
votes
1answer
143 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 ...
3
votes
2answers
191 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. ...
4
votes
1answer
89 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 ...
1
vote
0answers
195 views
Stored procedure to compare stored procedure result sets
Originally posted as an answer to a SOF question, this is about a generic procedure that allows back-end developers (e.g. SQL developers) to compare the results sets obtained by running two procedures ...
2
votes
3answers
771 views
SQL Procedure that will calculate the Last Price paid for a certain Part
I am trying to write an SQL Procedure that will calculate the Last Price paid for a certain Part.
...
8
votes
2answers
177 views
Execute every Monday that is not the Monday following last Saturday in month
I think the following is good but wondering if it can be simplified or improved.
My condition for code execution is the following:
It is a Monday
AND
It is not the Monday following the last Saturday ...
5
votes
1answer
573 views
Coin flips and Dice rolls in a stored procedure
I saw a post in chat a few days ago, of what I thought was an interesting (albeit fairly simple) statistical challenge:
By @skiwi:
If I shoot once with 50% chance of target A and 50% of target B, ...
10
votes
2answers
291 views
Executing a stored procedure with optional attributes
Lately, I have been reading Uncle Bob's Clean Code book, and decided to try and follow some of his principles to make a class that was a somewhat confusing static helper class, with an abundance of ...
5
votes
1answer
143 views
T-SQL Pbdfk2 (Rfc2898 SHA2_256) Implementation
Using my previous function as a base I've come up the following:
...
7
votes
1answer
793 views
T-SQL Hmac (Rfc2104 SHA2_256) Implementation
I'm trying to implement an Hmac in T-SQL using this question as an guide. Please critique this:
...
19
votes
2answers
1k views
Find & Delete Duplicate Records on All Tables in current MSSQL Database
The purpose of this code is to search the entire database for duplicate records and produce a script that a user could then run to delete all of the duplicates.
The stored procedure takes the ...