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).
0
votes
0answers
15 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] ...
-3
votes
0answers
26 views
How to avoid “Error=Timeout expired.” in MSSQL Server 2012? [closed]
I'm trying to avoid the Timeout error in an Stored Procedure and I've done some changes (used Try/Catch block) in sp to achieve this. Can anyone here please review ...
4
votes
1answer
89 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 ...
1
vote
0answers
12 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 ...
0
votes
0answers
17 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
19 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
30 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
46 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
0answers
26 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
0answers
31 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 ...
1
vote
1answer
33 views
Acquiring earnings information
The first part of the query grabs Policy's Premiums, Effective and ...
10
votes
2answers
361 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
27 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 ...
3
votes
0answers
23 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
15 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 ...
0
votes
0answers
12 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
36 views
Generating email with BCP
This code iterates through the table @Table1 to get the Purchaser, PurchaserID, ...
4
votes
1answer
116 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
84 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
102 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
154 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
183 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
955 views
7
votes
1answer
52 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
52 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.
...
10
votes
2answers
223 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
40 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
2answers
114 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 ...
2
votes
2answers
150 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
47 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
59 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
61 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
100 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
49 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 ...
3
votes
0answers
61 views
Query for a ticket system involving cases and casts on many attributes
I have this SELECT statement that inserts into a temp table and it is slow! Right now it takes ~1500 ms to run and only deals with ~7000 rows. As the data grows ...
7
votes
2answers
49 views
Retrieve high views per day questions with few answers
I've been messing around with the SE Data Explorer and I've come up with a query that basically returns information about questions that have a high number of views per day, that have few or no ...
-1
votes
2answers
114 views
Calculating price with a sub query
So I have this sub query:
*(select p.value1 From Params as p where p.PAR_Field = 'Taxe' and p.PAR_KEY = 'TVA')*
And I was using it 3 times to get the same value.
...
2
votes
1answer
29 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 ...
3
votes
1answer
51 views
Database design for users' postcards
I would like to a review of my database design.
There are 3 tables + ASP.NET Identity tables.
The Users could have many postcards.
Here's my tables without Identity.
I attached also my scripts of ...
1
vote
0answers
64 views
0
votes
1answer
37 views
Repair orders query in SQL Server with subselects
I was wondering if you guys know how to reduce the amount of subselects in this SQL Server Query? I think I'm using bad practices in this:
...
7
votes
2answers
132 views
Database credentials and connector including encryption
I'm designing a small Java desktop application to interact with my database and this is a very important part of it as a majority of the operations will be involving the SQL Server 2012 database. I am ...
4
votes
0answers
78 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 ...
10
votes
0answers
77 views
Parameterized Chutes & Ladders simulator using SQL stored procedure
I thought this would be a fun exercise to use SQL to participate in the June 2016 Community Challenge, so I did. Yes, you may call me crazy!
I had to write a few little things to help me, I needed a ...