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
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
809 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
582 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
421 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
2k 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
82 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
51 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
154 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
42 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
119 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
74 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
178 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 ...
16
votes
1answer
263 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
49 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 ...
4
votes
3answers
80 views

Data import “upsert” from a SSIS package

I have the following "upsert" trigger in SQL Server 2005, which is handling a large data import from a SSIS package. It is taking a very long time to complete - I suspect due to the concatenation and ...
2
votes
1answer
65 views

Demographics information for EDI report

I am going through some of my companies EDI reports to see if I can make them faster. The query below runs in less than one second in our AWS RDS environment, but it takes ~55 seconds on a blade in ...
3
votes
2answers
470 views

SQL query with nested subqueries

The following query is taking over 800ms to run, and returning 300 rows. When deployed to SQL Azure, it takes much longer on an affordable price tier. ...
2
votes
1answer
128 views

Query column names and then using them in statements

I currently have a table with over 250 columns, in which ~10-15 columns have column names that have a specific prefix, namely EQP_. Assume that you do not want to ...
2
votes
2answers
538 views

Copy Data from Informix to SQL Server

The following method copies data from Informix db to SQL Server db and it's so slow, I want to refactor it so it could be more readable and faster: ...
1
vote
0answers
34 views

Exclusive row lock

I'm in a situation where I need to manage a kind of FIFO process within a SQL procedure. The procedure is called by a multithreaded windows application. I've created a table which look like this: <...
1
vote
0answers
519 views

Current .NET session username injection in SQL Server stored procedures

I have a legacy WCF service that is ported from a security model using database logins and roles to a custom security. One effect of this change is that stored procedure are no longer executed using ...
1
vote
1answer
83 views

Finding all delivery orders with multiple purchase orders

I have a SQL query to find all delivery orders with multiple purchase orders (one-to-many). Is there a better or shorter way to write this? ...
1
vote
1answer
121 views

Convert MS SQL datetime to Oracle varchar(32) interval

I have a query against an MS SQL database that takes the resulting dataset and stores it in an Oracle database table which then gets joined to another Oracle table using the column ...
2
votes
0answers
29 views

Generating days in a specific range

I have a query in MSSQL, where I get a summary by days from a range in a table, and this is in union with other queries. This query is used to generate days in a specific range, then add the registry ...
2
votes
2answers
230 views

Update user country based on IPv4 decimal address

I have UserSignatures, a table with clientIPs, some of which have CountryIds that are null ...
0
votes
2answers
171 views

Get parent folder ids by folder id(s)

My Scenario: #TmpDistinctFolderIds table contains one or many FolderId. ...
3
votes
2answers
115 views

TSQL query to gather amounts for an employees, spouses, and children in one row

I have a query that works as intended, kind of pulling from multiple records in a table, and flattening the data into one row. I am wondering if there is a faster/more semantically correct way to do ...
2
votes
1answer
3k views

Python Pandas Apply with a Lambda Function

I have a table in pandas that has two columns, QuarterHourDimID and StartDateDimID ; these columns give me an ID for each date / ...
1
vote
2answers
73 views

Pivot script for sales numbers

I've recently been tasked with migrating some code stacks for an applicatin that is moving from using Access to using SQL-Server. I don't usually use PIVOT all ...
4
votes
1answer
116 views

SQL procedure for Archiving and Deleting

I have a requirement for archiving 5 huge tables from PROD to ARCHIVE server without losing the integrity of the tables. The query makes use of the Linked Server functionality and current idea is to ...
5
votes
1answer
2k views

Database trigger to monitor insert/update events and update another table

I am working on a MSSQL Database (for a program called Sage 200). There are many tables in the database, however, I want to be notified of changes (new record inserted or existing record updated) via ...
4
votes
1answer
98 views

T-SQL Secure String Comparison

The previous version of my function was scalar-valued and employed a WHILE loop to do the comparison, this is SLOW. This new version is tabled-valued and uses a typical tally table in place of the ...
2
votes
1answer
69 views

Stored Procedure enhancement for updating columns in a subset

The purpose of this store procedure is to reach into a large database (test), query for a subset, and update a column value, but with a big constraint - I can only update one row at a time in order to ...
1
vote
1answer
24 views

Get top row for muliple registers

I came across a piece of code that generates SELECT queries from a template. The template: ...
1
vote
0answers
819 views

WCF service architecture when SQL Server direct table access is not allowed

Part of my job is to maintain an old application written in Silverlight talking to a WCF service which in turn fetch/persist data into a SQL Server database and in a BI cube. Most of the security is ...
3
votes
1answer
143 views

Stored procedure to query custom data tables as dynamic SQL

There's a lot going on here, but the background for why this is necessary is that there is a set schema, or 'core' set of tables that are prefixed with 'bu', and any core table can have a custom table ...
0
votes
1answer
28 views

Finding colors that have not been assigned to a given user

Goal: make this code as efficient as possible. Given a finite dataset (Colors - this isn't Crayola here :D) how do I know what colors are not assigned to a given user? Additional requirement - the ...
-2
votes
1answer
129 views

Sample SQL Server code using pivot table

I'm using a dynamic pivot example. This SQL code has the purpose of perform transposing data from rows to columns, using a temporary table in SQL Server. The data is initially presented this way: <...
2
votes
1answer
103 views

MSSQL query to look for duplicate record

This query took 6 seconds to complete. How can I optimize it? Total records in table is 166803. ...
3
votes
2answers
191 views

Insert or update user data

I inherited an application that uses some stored procedures. Here is a sample of one of the stored procedures used to insert or modify user data. would like to get the group's opinion on the code. ...
2
votes
2answers
1k views

Powershell script to iterate through folder and restore SQL backups

I am working on a PowerShell script which will loop through a directory containing SQL Server database backup .bak files; move the files to a different location; restore each of those files to the ...
4
votes
1answer
89 views

Stored procedure to classify policies by sales date

Currently this is the store procedure I am working on, it is working according to some testing that was done. I feel that it could be improved though, could use some optimization, feedback or ...
7
votes
2answers
99 views

Deduplicating value pairs between 2 columns

This was asked in the SQL Helpline room: ...
0
votes
3answers
54 views

Counting pending bookings using a subselect

Can this query be improved? Is there a way to eliminate the duplicate function call? ...
6
votes
2answers
88 views

Top Python badged users from NYC

I forked this StackExchange Data Explorer (SEDE) query from another one, and made it a bit more complex. I'm looking for feedback on my style, as well as answers to other questions (see below). ...

1
3 4
5
6 7
12