Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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.

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

A procedure that receives a letter and a number that shows for example : (A,3) A AA AAA

Make a procedure called paintletter, it receives two parameters, a letter and a number. it will have to paint on the screen lines with the specified letters starting with a letter and ending with as ...
user avatar
3 votes
1 answer
36 views

MySQL procedure to extract a letter from a phrase

Create a function called GETLYRICS, which will receive as parameters a word of at most 15 letters and a number. It must return the letter of the position indicated in the number. My exercise is fine ...
user avatar
0 votes
0 answers
31 views

Extract the divisors between dividing and divider

It turns out that I have to do a procedure called THEDIVIDERS which receives two numbers for parameters, in my case the parameter 1 is by dividing and the second divisor parameter. Statement : Make a ...
user avatar
2 votes
1 answer
36 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 ...
user avatar
1 vote
1 answer
52 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 ...
user avatar
1 vote
0 answers
34 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 ...
user avatar
  • 111
1 vote
1 answer
69 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 ...
user avatar
2 votes
0 answers
39 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 ...
user avatar
4 votes
1 answer
877 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 ...
user avatar
  • 141
3 votes
1 answer
147 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 ...
user avatar
  • 185
1 vote
1 answer
97 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 ...
user avatar
  • 111
1 vote
0 answers
178 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 ...
user avatar
  • 500
1 vote
1 answer
196 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 ...
user avatar
  • 1,255
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 ...
user avatar
  • 21
3 votes
1 answer
39 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 ...
user avatar
0 votes
1 answer
64 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 ...
user avatar
  • 286
11 votes
1 answer
283 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 ...
user avatar
  • 18.3k
2 votes
1 answer
46 views

Inner Join only if satisfies If condition

I'm looking for code review, and optimizations. I have two tables ItemCategory and ShopItemCategory ItemCategory ...
user avatar
  • 119
6 votes
1 answer
880 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 ...
user avatar
1 vote
2 answers
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 ...
user avatar
  • 113
1 vote
0 answers
154 views

Insert complex object into multiple sql server tables

I am inserting data into three tables Properties, Rooms and RoomImages, using a stored ...
user avatar
  • 123
1 vote
0 answers
1k 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 ...
user avatar
  • 261
1 vote
2 answers
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 ...
user avatar
2 votes
2 answers
98 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 ...
user avatar
  • 31
3 votes
1 answer
34 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 ...
user avatar
  • 875
6 votes
1 answer
72 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 ...
user avatar
5 votes
2 answers
741 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 (...
user avatar
2 votes
1 answer
165 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 ...
user avatar
2 votes
1 answer
81 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 ...
user avatar
1 vote
1 answer
141 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 ...
user avatar
5 votes
1 answer
42 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 ...
user avatar
  • 51
2 votes
2 answers
711 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 ...
user avatar
  • 121
1 vote
0 answers
982 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: ...
user avatar
3 votes
1 answer
278 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 ...
user avatar
2 votes
1 answer
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 ...
user avatar
  • 23
6 votes
1 answer
207 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 ...
user avatar
  • 20.3k
1 vote
0 answers
70 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? ...
user avatar
3 votes
2 answers
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 ...
user avatar
1 vote
0 answers
525 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 ...
user avatar
  • 1,786
4 votes
1 answer
133 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 ...
user avatar
5 votes
1 answer
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 ...
user avatar
  • 293
2 votes
1 answer
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 ...
user avatar
  • 169
3 votes
1 answer
149 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 ...
user avatar
  • 131
3 votes
2 answers
194 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. ...
user avatar
  • 336
4 votes
1 answer
96 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 ...
user avatar
  • 143
1 vote
0 answers
203 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 ...
user avatar
  • 1,786
2 votes
3 answers
1k 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. ...
user avatar
  • 475
8 votes
2 answers
182 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 ...
user avatar
  • 497
5 votes
1 answer
657 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, ...
user avatar
  • 20.3k
10 votes
2 answers
301 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 ...
user avatar
  • 355