The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
3
votes
4answers
1k 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
61 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
14k 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
142 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
118 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
55 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
284 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
389 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
123 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
67 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
88 views

Generating email with BCP

This code iterates through the table @Table1 to get the Purchaser, PurchaserID, ...
4
votes
1answer
808 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
75 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
198 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
780 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
770 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
469 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
388 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
77 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
151 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
101 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
73 views

SqlCommand filter by dates are slow

I have these codes(.net framework 2.0): ...
0
votes
1answer
38 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
4k 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 ...
6
votes
1answer
173 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 ...
15
votes
1answer
235 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 ...
3
votes
2answers
48 views

Finding maxDate for each entity

I have a table with (CompanyNumber, File_Date, [various financial results]) I wanted to get only the most recent set of accounts for each company. After various ...
5
votes
2answers
62 views

Adding dynamic column names to a table

I'm using Microsoft SQL Server 2014 Express. I found myself wanting to add the Columns CompanyNameChangeDate (1 through 10) and ...