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
6
votes
1answer
201 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 ...
3
votes
3answers
43k views

Inner join with first result

In SQL Server, there is two tables: Houses, and their images. I need a list with 20 houses with the first of their images (only one). I tried: ...
1
vote
1answer
96 views

Update Trigger (Comparing Descriptive string), as well as checking for valid updates

I have an audit table EpisodesHistory. One of the fields that gets copied is eDescription. I expect ...
1
vote
1answer
536 views

Ontario Health Card mod 10 validation

An example of the business rules are here. Does this code implement those rules correctly? Note that you will have to derive the rules from the example. ...
0
votes
1answer
40 views

Selecting data from a table based on value in another table (SQL server)

I am using the northwind example database to brush up my SQL server skills. I want to select all the products ordered by the customer with the customer id 'Folko'. My idea is to join the Orders ...
3
votes
1answer
50 views

Comparing columns values and change their places by condition

There are three simple tables. Actor, Film, Film_actor. ...
34
votes
7answers
284k views

Select first value if exists, otherwise select default value

Given an instance of SQL Server, imagine there's a table named Configuration, which has three columns: ID, ...
0
votes
1answer
45 views

Concatenating results in a comma separated list

I am trying to list all of the employees linked to a certain 'Interaction' I want the employees listed on one line with comma's separating them, I have the following query which works but is very slow....
0
votes
1answer
80 views

Looping in SQL Server to insert row into table at top

Here I have a stored procedure that seems to be taking a little longer to run than I had hoped for. What made this algorithm so lengthy was the fact when adding an element to a new table in SQL it ...
1
vote
0answers
169 views

Exposing LocalDB API to VBA

SQL Server has had LocalDB since 2012. The main primary purpose for the LocalDb is to support developers without requiring a full install and running a service. However, a LocalDb can be also used in ...
3
votes
2answers
129 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. ...
4
votes
1answer
705 views

Multilingual website with a database

I created a multilingual site in MVC and I reached the current results, but I'm not sure it's the right way. I have created a class named changeLanguage to change ...
1
vote
2answers
57 views

Stored procedure for processed orders in SQL Server

I am struggling with creating a Stored Procedure in SQL Server for getting sales statistics. I have managed to get the information I need out, but the query is a mess and I have probably messed up the ...
2
votes
2answers
2k views

SqlCommand ExecuteReaderAsync helper method

The following helper method executes commands asynchronously and returns a Task<IEnumerable<T>> where T is a type that receives the row information from ...
1
vote
0answers
476 views

Selecting coins with alert count by using a subquery

I have a table called alerts and is related to a table called coin (coin can have many alerts). I would like to return a list of alerts but also return a subquery count of how many alerts that coin ...
1
vote
2answers
54 views

Getting data from two tables

This query gets data, but for 116819 rows I need to wait 2:19 minutes. Getting the same data from the table takes 2-3 seconds, but I need some rows from the view (that are matching my data from table) ...
2
votes
1answer
588 views

Duplicate Payments using SQL

Working on identifying duplicate vendor payments using SQL in MS Access. The business logic uses four column; Vendor #, Invoice #, Invoice Date and Invoice Amount. There are 5 core reviews, if all are ...
4
votes
2answers
321 views

Connection String Decorating

I found myself in a situation where it is necessary to often decorate connection strings with some kind of metadata, like an extra DB Provider attribute, read it back, and remove the decoration ...
1
vote
1answer
932 views

EF Core Complex Query Method

The code is returning reviews based on users like status order. It seems it executes a lot of SQL queries, so do you think it can be simplified and can it be a headache to server performance? ...
3
votes
1answer
117 views

Speed up SQL query

I have a query that I need help with speeding up. Right now it takes long enough that it often times out. I do know that the part of the query that times out is part of an ...
3
votes
1answer
7k views

Converting local currencies into one target currency using the exchange rate table

The solution is to be used on MS-SQL server. The presented code was tested on MS-SQL 2012. I was given the exchange_rate table that reflects the human interface (...
1
vote
1answer
167 views

Performance concerns for synchronous action methods

I have an ASP.NET MVC 5 application using Entity Framework with SQL Server 2016. The application is mainly basic CRUD. The boilerplate generated when creating the project in Visual Studio did not have ...
1
vote
0answers
55 views

CF/SQL Query using window functions

I am very new to MS SQL Server and am trying to learn how to combine window functions within my SQL query. I have two tables that I have to tie together using assoc_id and associate so that I can set ...
2
votes
2answers
51 views

Replacing a variable in a loop by records from a Table

I have a Date Table like this one: Exit_Date Date_ID 2017-05-31 1 2017-04-26 2 2017-01-02 3 2016-12-24 4 2016-11-27 5 I use a loop to insert each ...
2
votes
1answer
75 views

Adding data to database using ASP.net and SQL-server part 2

This is a continuation of my question in this link: Adding data to database using asp.net and sql-server. Now I have already incorporated the solutions that was provided in the given link. First ...
3
votes
3answers
590 views

Querying employee schedules in a month [closed]

I have this code, this code querying employee schedules in a month, in a work unit. If the List<Employee> count are few, the code works great, but if the <...
3
votes
1answer
102 views

Adding data to database using asp.net and sql-server

I just want to know your suggestions on improving my code on adding data to the database using asp.net and sql-server. Basically, I've created a form that the admin will fill-up and then when he ...
7
votes
5answers
6k views

Database schema for a school

Here is the database query needed to create the database: ...
2
votes
2answers
95 views

SQL Server Stored Procedure quality

I'm beginner in programming and I have recently written quite an advanced stored procedure. Based on parameters with which I call it, it returns data and groups it, but that is not the most important ...
4
votes
2answers
33 views

Copying dealer attributes from one row into rows for other branches

I am writing an update statement where I need to have multiple rows of data duplicate an existing line with everything but the principal and branch id. I am fully aware that this code is not the best ...
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
0answers
42 views

Check status of all child generations of medical claim [closed]

When a medical claim is replaced, it gets a new number. The older version is supposed to get cancelled out, but this doesn't always happen successfully yet at my workplace. I wrote this to try to aid ...
2
votes
1answer
45 views

Query to use the longer of two date-time ranges

I have a complex date-and-time-matching query in the middle of another huge query. I'm matching two tables, the second one is LEFT JOINed to the first. If the time ...
3
votes
2answers
56 views

FInd the correct Casing description from process tracking - Scalar Function

It works as intended, I just wonder if there is any stylistic things I could improve. It already runs well fast enough, although I'd be open to speed increases. This SQL Server 2008 Scalar Function ...
3
votes
1answer
9k views

Stored procedure to write in a file

The following stored procedure allows me to write in a file stored on my SQL Server: ...
3
votes
1answer
82 views

Calculating employee points

I have one table on which I want to perform some calculations. The table stores employee points that are awarded for performing various tasks. The relevant structure is as follows (table has about ...
3
votes
2answers
141 views

Return office details from multiple tables

The function itself is just returning as void. But, the point of the posted code is not about what the function is returning. It is the code related to using T-SQL ...
3
votes
2answers
199 views

Computing dates and counts

I have a big SQL request where I compute dates or counts (from other tables), and I have to compute new dates based on conditions on those pre-computed dates and counts. In the following example, I ...
5
votes
2answers
75 views

Convert strings from OW format to ADE format using many regex replacements

I have a working C# (version 5) function that I use to match an input string to one of many unique regular expression patterns and return the replacement string associated with the matched pattern (...
1
vote
2answers
183 views

Fire same Task after 1 minute

I am storing incoming data into SQL server database In storing process assigning group Id for 3000 records I have written windows application that check new data is incoming into the database. first ...
1
vote
1answer
37 views

Multiple joins for fields that need the same data. SQL Server 2008 R2

I'm hoping I can find a better way to do this. I've tried this with a join with multiple 'OR' statements (I know it's terrible), and with multiple joins as shown below. ...
1
vote
1answer
99 views

Delete duplicate entries with lower IDs

I have a function that deletes duplicate entries. The highest ID is kept and the older ones are removed. function: ...
7
votes
3answers
199 views

Inefficient query actually more efficient?

I have two queries; one runs significantly faster than the other, but the faster one is the one that I would have bet money on to be less efficient. These are both being executed through a front end C#...
1
vote
1answer
656 views

ROT47 function implementation

According to Wikipedia, here below is the definition of the algorithm: ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with ...
3
votes
1answer
7k views

Retrieving data in an SQL database and displaying the retrieved data in ASP.NET

I wanted to know other ways where you can access data from the database into the asp.net website that I've created for displaying details and images. As well as looking for better ways to use those ...
19
votes
3answers
1k views

FizzBuzz in SQL--no loops

MS SQL Server, no loops. ;) ...
7
votes
3answers
15k views

SQL database design for ecommerce

I need to create a database which stores details products, Manufactures,Suppliers. So initially I divided Products into categories and subcategories. These are the tables I created. ...
3
votes
1answer
81 views

Get element at a specific position in a string with separator

I have created the following user defined function in order to get the element at the position POSI (starting at 0) in the string ...
1
vote
1answer
49 views

SQL subquery to determine whether or not a particular row is the first item that matches the subquery

Here is my VB.NET and SQL query (which is one of the things I'm particularly interested in having critiqued): ...
0
votes
1answer
554 views

Normalizing an apartment rental database [closed]

We are to normalize a database, though it is mostly all theoretical, we aren't actually plugging in the SQL. This is the Data we have normalized to these tables.. and here is our SQL for normalizing ...

1 2 3
4
5
12