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
2 votes
1 answer
28 views

Are there other means to apply place holders to an array in a loop for pdo statements for search functions with unknown numbers of keywords in php

I'm a newbie to PHP and other programming for that matter. I'm doing this simply to learn. Figured the code could be used to search through a police database or something. The statements are Microsoft ...
Luke Lenacio's user avatar
2 votes
1 answer
66 views

Find All Recent Winners and Calculate an Encoding of What They Won

Context I was proud of this code for a little while, but the repetition wounds me. I know that the function name sucks, but the name and interface to this function are not under my control. ...
J. Mini's user avatar
  • 117
2 votes
2 answers
82 views

Find All Recent Winners and Calculate an Encoding

Context I was proud of this code for a little while, but the repetition wounds me. I know that the function name sucks, but the name and interface to this function are not under my control. ...
J. Mini's user avatar
  • 117
1 vote
1 answer
107 views

What is the percentage of customers who increase their closing balance by more than 5%?

The Question What is the percentage of customers who increase their closing balance by more than 5%? Source Code The database and all details can be found here. ERD My Proposed Solution ...
Mike's user avatar
  • 113
1 vote
1 answer
146 views

Efficient Connection Pooling in ODBC-MSSQL with Rust (odbc-api)?

I want to connect to MSSQL using ODBC (odbc-api) at the beginning of my server application created with hyper.rs. I want to have a connection pool and obtain a connection within each request, which ...
dertin's user avatar
  • 11
0 votes
1 answer
109 views

Is there a more concise way to write this Procedure

I have this stored Procedure that is passed in the data below that will building the SQL select that will get EXEC. The data that can be passed in can me null so I have three ...
Jefferson's user avatar
  • 359
1 vote
1 answer
61 views

Is there a more concise way to write this query in SQL Server?

I'm playing with data from a Time Use survey as a beginner SQL user. Gender is represented as 1's (Male) and 2's (Female), and the age of each participant is listed. I would like to divide them into ...
Erik's user avatar
  • 303
0 votes
0 answers
38 views

Changing the state of an entity in a multi threaded environment using Stored Procedures

According to my current design various processes and threads(written in .net core or framework) will call this stored procedure to change the status of various entities in a multi threaded environment:...
Spongebob Comrade's user avatar
1 vote
1 answer
244 views

Employee Attendance structure design

I am designing a solution to store employee day attendance, which can be recorded either as hours or as an interval within a day. The goal is to maintain a monthly attendance list for each employee. ...
Andrius's user avatar
  • 119
1 vote
3 answers
864 views

Write SQL Server table to Parquet file

This is a C# console application that creates Parquet file for SQL Server table. Given a 5GB SQL table, it takes nearly 65 minutes, so for our bigger tables (up to 500GB), it may end up taking days to ...
Srini's user avatar
  • 11
0 votes
1 answer
106 views

Count how many active and inactive users are in a group/unit/department/team

Given the following example data: id username group unit department team status 1 user1 g1 u1 d1 t1 active 2 user2 g1 u1 d1 t2 active 3 user3 g1 u1 d1 t3 inactive 4 user4 g3 u6 d12 t30 active 5 ...
pileup's user avatar
  • 361
-2 votes
1 answer
51 views

Optimizing a TRANSACT SQL statement [closed]

I'm in need to optimize the following TRANSACT SQL statement : ...
Simone Spagna's user avatar
3 votes
0 answers
46 views

SQL query to pivot table into dynamically growing set of columns

I am working on SQL Server I have sample data like this in a table. CustId Bank city rating date rnk 1 Deutsche Delhi 5 10/10/2022 1 1 BOA Pune 6 10/10/2022 2 1 UBS Mumbai 7 10/10/2022 3 1 SBI ...
user3580341's user avatar
0 votes
0 answers
47 views

Query to get data out of a dirty database

Preface / Background Feel free to request for more information about the data and please let me know of redundant information I can remove to help keep this question as clear as possible. I do not ...
Mandelbrotter's user avatar
-1 votes
1 answer
50 views

Nested table in query

I have transaction tables called MaterialRequest and MaterialRequestDetails. What I want to check my query and review that it's ...
Basit Sarguroh's user avatar
1 vote
1 answer
46 views

Select certain row if it is in the date range otherwise take fallback

SQL Server 2017 The table contains duplicate contracts per factory with different From and To dates. I'd like to select the correct row based on a declared YearMonth parameter. If this falls in the ...
Peter S's user avatar
  • 111
1 vote
1 answer
70 views

updated Accounting system data database design

Many thanks for your valuable comments in my previous post. In my previous link Accounting system data database design The primary key and foreign key was not assigned i was thinking handle from front ...
Basit Sarguroh's user avatar
3 votes
2 answers
503 views

Accounting system data database design

I have created an accounting database as per my accounting knowledge. I want to check: Is that database correct which I design for the accounting system? I have table called Mst_AccountGroup(Asset,...
Basit Sarguroh's user avatar
0 votes
1 answer
51 views

Find dogs who stopped being good boys without ever being good boys - Was HAVING the wrong approach?

The problem I have solved is as follows: Consider a table of dogs, DOGGIES, that records on each row the ID of a doggy, one ...
J. Mini's user avatar
  • 117
1 vote
1 answer
73 views

batchUpdate using pdo and MSSQL

...
Sayaman's user avatar
  • 299
1 vote
1 answer
122 views

Creating database and two tables linked by foreign key

These commands do what I want, but I'm trying to find out the best approach for this. My main areas of concern are: error handling and disposal of resources. In regards to error handling, I'm catching ...
Pablo Aguirre de Souza's user avatar
6 votes
0 answers
232 views

dotnet - creating db records in bulks in a background job

UPDATE: I found the namespace Channels, and this does exactly what I want to do, but in a much more stable way. Please don't use my code for anything important! :) Use case I have a site that (at peak ...
Stephan Møller's user avatar
-2 votes
1 answer
51 views

T-SQL Query Performance [closed]

The query below already has indexes based its execution plan but it is still under performant with larger datasets. Are the additional null checks needed and why? Do you see anything that can be done ...
Rick B.'s user avatar
  • 135
1 vote
1 answer
341 views

Database schema for discussion forum scraping

I'm scraping posts from various discussion forums and storing those posts, along with some metadata, into a relational database (SQL). My actual use case is a bit more complex, but I think I can give ...
Dan Tony's user avatar
0 votes
2 answers
40 views

Table-Value Function with row-level-locking

I'm implementing row-level-locking on a MS SQL Server. The function I created below works, but even with a very small data set, it takes a significant amount of time to return the results. If I were ...
rohrl77's user avatar
  • 181
1 vote
1 answer
2k views

Get result of a scalar-valued SQL function from C#

I do not receive files on holidays; I only receive files on regular days—i.e., non-holidays. I want to skip 2021-09-06 since that's a holiday (Labor Day) and I know I will not receive any files. ...
Anonymous29's user avatar
-1 votes
1 answer
70 views

IF SELECT statement will break SQL ACID Compliance? [closed]

My QA told me that I should not use IF SELECT before doing an UPDATE statement because it will breaks the atomicity of a ...
vantian's user avatar
  • 141
3 votes
2 answers
119 views

Alter authorization on all non-system SQL Server databases

I am not very experienced with T-SQL and feel this can be done better. The script changes ownership of all "user" (non-system) databases to sa. Usage of a ...
Igor Soloydenko's user avatar
2 votes
2 answers
66 views

Complex reporting query suggestion needed for different approach as per latest Tsql format

We have recently migrated from SQL Server 2008 R2 to SQL Server 2017 web edition. I am not a SQL developer but enthuses to learn. Since many of our scrips are of old SQL format, I am searching for ...
Aditya Sawant's user avatar
3 votes
3 answers
112 views

Retrieving restaurant orders from SQL Server [closed]

...
SolentCIS's user avatar
3 votes
2 answers
772 views

PySpark SCD Type 1

I am using PySpark in Azure DataBricks to try to create a SCD Type 1. I would like to know if this is an efficient way of doing this? Here is my SQL table: ...
AGB's user avatar
  • 31
1 vote
0 answers
25 views

Re-organizing indices in case of fragmentation is T-SQL

In order to keep the fragmentation ratio of indices low, you should re-organize the indices from time to time on MSSQL. Microsoft describes in the link below how you can check the fragmentation of ...
gil.fernandes's user avatar
4 votes
1 answer
191 views

Basic schemas for database and tables creation, bulk import from .csv and basic queries

The following SQL code serves the purpose of assessing basic SQL Server literacy. I am creating database and tables schemas, inserting data from .csv files. Constructing 8 simple queries as answers to ...
I. Я. Newb's user avatar
0 votes
1 answer
283 views

SQL Query to perform a "reverse exclusion" on a LEFT JOIN with a select from the left side table

I have a set of tables that I want to execute a LEFT JOIN on and bring back "excluded" rows. In addition, I would like the left table's ID included as ...
akousmata's user avatar
  • 101
1 vote
2 answers
142 views

Optimizing database access using LINQ [closed]

I have the following method that I am trying to optimize. Currently, the method works great, however, it takes a little over 3 hours to complete. I feel like, using some nifty LINQ joins, it should be ...
Icemanind's user avatar
  • 188
1 vote
1 answer
174 views

Retrieve data from two different rows in a single SQL query?

I've a table with the following data and I need to find the number of minutes between two jobs (Say A and C). The following query works but wondering, if there is a simpler way to achieve the same. <...
nsivakr's user avatar
  • 163
3 votes
2 answers
121 views

all appointment based on interval distance

Currently with a given Date and an Interval in Day, I can calculate all of the appointment in the future. for example if you are ...
Masoud R's user avatar
2 votes
0 answers
38 views

Basic login by username logic with SQL Server

My goal is to make a very simple library with the authentications basics: create a user and save its hashed password, change its password, have a method to check if the password is correct for login. ...
user avatar
2 votes
1 answer
241 views

How to make this query better (e.g. avoid repeating subquery in a query)?

Stack Exchange provides access to query their MS SQL databases. They have a table Posts where each post is either a question or an answer (see the schema on right ...
Tim's user avatar
  • 121
2 votes
1 answer
39 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 ...
Mohammad Safyar's user avatar
2 votes
2 answers
140 views

Receive data from SQL and CSV and send it to MySQL database using Python

Details: I have a code, which does the following: Get data from CSV and insert it into MySQL table Get data from SQL Server and insert it into MySQL table Run this code every 240 seconds - to ...
Eduards's user avatar
  • 225
1 vote
0 answers
32 views

Code for tracking changes and deletions to tables

I have written a SQL server stored procedure to generate "log" tables which store the old values of rows when a table is updated, and also record when rows are deleted ( and by who ). It's quite ...
George Barwood's user avatar
2 votes
0 answers
46 views

API Layer ClientId and Security style

Im at the point where I am designing my api security and I was going with a custom attribute I don't want to use third party systems as they cost money. I was going to use the client id and the ...
c-sharp-and-swiftui-devni's user avatar
1 vote
2 answers
440 views

Faster/Better Processing for SQL While Loop

I have a list of about 55k Accounts that I am cleaning up. 95% of them are from US/Canada which is what I'm most concerned with. I am going through record by record and will perform various checks ...
Dizzy49's user avatar
  • 201
1 vote
1 answer
34 views

Calling a function within stored procedure to derive a value

I am trying to write a sql storeprocedure that basically returns a derived value from an outcome of a function call. The derived field returns the difference in days and if the difference is less ...
Tom's user avatar
  • 217
1 vote
1 answer
114 views

Get average post score of TOP 10 tags on StackOverflow using Stack Exchange Data Explorer

I want to use the Stack exchange data explorer in order to display some basic information about the top tags. The query should print the number of questions and answers, the average number of answers ...
dan1st is crying's user avatar
3 votes
3 answers
833 views

Export sql data to xml and csv

I have the below code that takes the sql data and exports it to xml or csv. The xml is processing at good speed but my csv sometimes takes 1 hour depending on how many data rows it exports. My ...
QuickSilver's user avatar
3 votes
0 answers
419 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
147 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
228 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

1
2 3 4 5
12