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).
5
votes
1answer
22 views
Query to get distinct items at the top of results and duplicates following
I need to query the table below and list the distinct items at the top of my result set and the duplicates will follow, the order of the duplicates does not matter.
I am working with Sql Server 2016 ...
1
vote
0answers
13 views
Temporary procedure to update/insert settings
I have several applications and each of them has its own [Setting] table. They are also in different schemas. In order to address this and to be able to use the ...
0
votes
0answers
12 views
How to reuse SQL subquery in a query? [on hold]
I am not sure how does it called, so I am not sure how to search for my need.
My MS SQL query:
...
-1
votes
0answers
30 views
Is there a way i could optimize this query [closed]
This query is taking 17 seconds to run and I thought I had all the indexes it was asking for, but I still can't get it down any more.
...
2
votes
1answer
33 views
-1
votes
0answers
48 views
SQL generates a dynamic table as an input for a Kendo UI table
I'm just registered to codereview.stackexchange. Please provide some feedback on this code.
I have a backend (ASP + SQL) and frontend Kendo UI. This SQL provides data to WebMethod.
Decided to ...
0
votes
1answer
57 views
Basic SQL aggregate query
I have an employee table, employees may have multiple peripherals. I want to bring back all employees that have a peripheral of type 1 or 2, but that don't have any ...
4
votes
1answer
84 views
Updating complex objects
I'm mainly looking at usage of Dapper, but in general, any comments relating SQL -> C# object mapping best practices would be appreciated.
I've got two super simple objects I'm working with:
...
3
votes
3answers
102 views
Saving complex business objects with reflection and recursion
In our application we have complex objects with many nesting levels, each with various properties that are important to the business. We currently serialize and persist these objects along with their ...
3
votes
4answers
465 views
Prompting user for connection parameters to SQL Server
I try to avoid keeping passwords etc. in memory or in plain text anywhere. But I am on a huge time crunch and this will only be used internally this week then probably won't get touched again. I just ...
2
votes
0answers
30 views
Generalizing work orders
I am working on designing tables for work orders.
The problem:
There is different work order models (from now on called WOM)
The WOMs share some attributes (Num, Date, Description, ... etc)
The WOMs ...
0
votes
0answers
27 views
Win-Loss Record in SQL Server
I'm building a database on Microsoft SQL server to teach myself SQL. I am a big UFC fan so I'd like to build a database on UFC fighters. I'm building two tables [fight] and [fighter]. The [fighter] ...
4
votes
1answer
153 views
Writing CSV file from huge JSON data
I am writing a program that reads from DB and outputs to a CSV file. Besides the regular columnar data there are 2 JSON fields data as well. The table layout looks like this (other fields removed for ...
2
votes
1answer
29 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 ...
1
vote
0answers
21 views
SQL Server: Lock rows on updating
I have multiple instances of an application (C# console apps) which needs to pick a set of records from a table and mark them (Update AllocatedTo with instance name), so that no other instances will ...
1
vote
1answer
26 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 ...
3
votes
1answer
41 views
T-SQL UDF to replace replace base URLs
I have a problem where I need to replace every base part of URLs in a body of text. However, I only want to replace it in specific URLs. Only URLs that go to "resource.aspx" that have the "source" ...
2
votes
0answers
48 views
Complex views are a little slow
I have this view vw_RFQPartVendor that's based on these two views vw_requestVendor and ...
3
votes
1answer
40 views
Replacing names in text fields with aliases to help de-identify data
I have a table with over 1,000,000 records. I need to replace any names in the text fields with aliases to help de-identify the data. For this example, let's assume the table is ...
1
vote
1answer
34 views
Optimize subquery that searches xml
The following query lists all domains from multiple companies in which a value occurs in an XML set. This is filtered to the most recent occurrence within a provided date range.
On large databases ...
2
votes
1answer
39 views
Acquiring earnings information
The first part of the query grabs Policy's Premiums, Effective and ...
10
votes
2answers
370 views
Who are these lurkers?
Last night in The 2nd Monitor there was a discussion about postless users - I wanted to see how many there are, whether they're one-timers that showed up once, registered and never came back, and ...
1
vote
1answer
29 views
Read uncommited rows and lock row on update
I have 5 (or more) instances of an application running on same or different machines. Each of these application will pass a comma separated string of UserIDs and the app should pick up a unique unused ...
4
votes
0answers
26 views
Find unused stored procedures/functions in SQL 2012
I was given the task of finding those unused procs/functions in our SQL 2012 database.
Initially my plan was to use the table sys.dm_exec_procedure_stats. I could set up a job to check the table ...
0
votes
0answers
16 views
Rescheduling long production tasks to the next day
The code below is used for a table with production tasks. It moves tasks to the next day where the sum of hours required for actions belonging to the same production order is more than 8.
The code ...
1
vote
1answer
23 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 ...
2
votes
0answers
38 views
Generating email with BCP
This code iterates through the table @Table1 to get the Purchaser, PurchaserID, ...
4
votes
1answer
154 views
Node js server that create, read, and update user data using TCP socket and AES encryption
I've written a Node js server that create, read, and update user data from a SQL server hosted in Azure. Clients connect to the server using a standard TCP socket, every message sent or received will ...
2
votes
0answers
108 views
Mapping Excel columns to table columns, then processing data
I have written some code for mapping excel columns to table columns and processing data after mapping columns. Please review this code, check for SOLID, OOP principles and suggest any improvements and ...
3
votes
1answer
41 views
3
votes
1answer
106 views
Complex report generator using huge SQL Query
As the title say, I have a huge SQL Query which was built over the time (as new requests came, fast workarounds were demanded).More, there were three DB Admins who contributed to this query, and I'm ...
2
votes
2answers
50 views
Rolling totals in a view
I have a view that performs some rolling totals. In this instance, it must be in a view. The issue is that it takes about 10 minutes to run, returning 2700 records. There should be a faster way, but I ...
3
votes
0answers
24 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 ...
1
vote
0answers
35 views
First unique record from update queue
The goal is to select the first change in the UpdateQueue on change of Unit or UnitsRelative....
2
votes
2answers
182 views
Creating a random code and saving if it does not exist
I have created a script to generate 5 random codes, check if any one of them exists in the database, and if not, insert the record. The script will throw an exception if a single code could not be ...
7
votes
2answers
195 views
SQL query to compare two XML columns
I need to compare two XML columns. I currently have about 1000 rows of data that this is running against and it takes about 20min. Is there anyway I can improve this query to run faster.
...
1
vote
1answer
28 views
Correlated subquery slow
I have a table that looks like this
Directory nvarchar(max)
Extension nvarchar(10)
Length bigint
I also have another table that provides the type of file (lookup table)
extension nvarchar(10)
...
6
votes
3answers
1k views
8
votes
1answer
65 views
Load and parse Stack Exchange data dump XML into DB table
I have put together a stored procedure to load and parse the Stack Exchange Data Dump into a relational database (akin to Stack Exchange Data Explorer). Each site has 8 XML files like these:
The ...
2
votes
2answers
58 views
Find items in a table that match a set of conditions in another table
I have two tables. Table 1 has sets of EXPORT conditions: e.g., SET 1 has FOOD, GARMENT, and TECHNOLOGY, and SET 2 contains GARMENT and TECHNOLOGY.
...
11
votes
2answers
250 views
Batch file to backup and update SQL Server DBs
This is my first windows batch file. The script basically goes through this basic flow of tasks, in order to update some specific SQL Server DBs to a new DB version:
Backup all SQL server DBs that ...
1
vote
0answers
41 views
3
votes
3answers
672 views
Fetching busy students and their latest product
I use SQL Server 2014 and I have three tables:
Student (ID, Name, Age)
Product (ID, Name)
StudentProduct (StudentID, ProductID, Date)
...
2
votes
1answer
156 views
Create database connection and run the insert, delete, update queries class-Update
Based on the feedback I have got from the guys reviewing the code as posted in my previous question.
Create database connection and run the insert, delete, update queries class
I have used ...
3
votes
2answers
164 views
Create database connection and run the insert, delete, update queries class
Recently while developing our demo project I had to a write a lot of repetitive code for executing the database queries (insert, update, delete). So, I have put all the repetitive code into a class ...
0
votes
0answers
57 views
Generic Polling Class and Using it to Poll SqlConnection
I have the following poller class that can be used to "poll the required action":
...
3
votes
1answer
64 views
Finding the Nth occurrence of character in string
I wrote an SQL Server function which returns the substring before the Nth occurrence of a character.
For example:
...
1
vote
1answer
67 views
Generate SQL for translated resources from Excel Spreadsheet
I do some work that involves translating resources for a webpage. These are all stored in a SQL Server table that looks like this (plus a few irrelevant constraints).
...
3
votes
1answer
107 views
Entity Framework query optimization
A user can track a show, and mark episodes and seasons of that show as watched. To support this I have the models below:
Models
...
0
votes
0answers
51 views
SQL BulkCopy - XML to SQL
The application we've built occasionally needs to load XML data into a SQL database. The code works well until the files reach 600kb or greater at which point out-of-memory exceptions occur. The ...