A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

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
0
votes
1answer
1k views

Exporting HTML table data to Excel using C#

I have JSON data that I bind to a table: Now I would like to export this data to Excel, so I have written this code that involves data formatting of an Excel spreadsheet. ...
-2
votes
1answer
79 views

Increase performance of INNER JOIN with subquery [closed]

Is there any way for optimizing the below query without further addition of any INDEX, if possible? ...
6
votes
2answers
69 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 ...
2
votes
1answer
37 views

Map groups to parent products using nested subqueries

I have the following tables ...
0
votes
1answer
70 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
1k 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: ...
2
votes
3answers
3k 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
2k 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
39 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 ...
1
vote
0answers
63 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
15k 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
145 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
31 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 ...
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 ...
3
votes
1answer
122 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
57 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
324 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
37 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 ...
4
votes
2answers
58 views

Acquiring earnings information

The first part of the query grabs Policy's Premiums, Effective and ...
10
votes
2answers
390 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
35 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 ...
5
votes
0answers
130 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 ...
1
vote
1answer
68 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 ...
3
votes
1answer
100 views

Generating email with BCP

This code iterates through the table @Table1 to get the Purchaser, PurchaserID, ...
4
votes
1answer
818 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
7k 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
52 views

Create new columns depending on the columns in a table

I have code in the this example: ...
3
votes
1answer
153 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
56 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 ...
5
votes
1answer
39 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
2k 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
3k 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
78 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
10k views

C# function to execute queries in a SQL Server database [closed]

...
8
votes
1answer
205 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 ...
3
votes
2answers
127 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
826 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
43 views

Searching news for a string value

I need to improve performance for query ...
3
votes
3answers
683 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) ...
3
votes
1answer
786 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
1k 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 ...
2
votes
0answers
494 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
2k 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
402 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
1k 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 ...
3
votes
0answers
79 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
153 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
41 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
104 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 ...