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).

learn more… | top users | synonyms (1)

3
votes
1answer
13 views

File Exists Script Task for SQL Server SSIS

I have an SSIS package for SQL Server 2008. In this package, I need to verify that a file exists that matches a pattern of SomeFileName_*.txt where the wild card ...
2
votes
1answer
23 views

Better way to divide by the total count SQL

I have this query where I am working out the percentage of peoples occupation, I have a sub query that works out the total count of people codes and that result is what I used to divide by, I could ...
11
votes
4answers
220 views

LW, MTD, STD, YTD Sales… all in line and looking pretty

That's Last Week, Month-to-Date, Season-to-Date, and Year-to-Date sales. I have a table-valued function for each one, that takes a date and returns all ...
10
votes
2answers
82 views

SQL-Server Merge Statement with .NET DataTable

Background: I'm trying to synchronize order information between Oracle and SQL-Server databases and allow users to be able to track any changes between what has been replicated via an ASP.NET web ...
2
votes
2answers
33 views

Assign Specific Value If BitField Is True

My colleague created this SQL to handle certain user selections which are based on an on/off bit flag. The goal is to identify those individual bit flags with a specific integer which will be used in ...
0
votes
0answers
7 views
3
votes
2answers
39 views

Extract last record inserted for each key identifier

I have a table with this schema ID, int primary key PathKey, string not null InsertDate, datetime not null Value, int not null In the table there are a ...
3
votes
2answers
74 views

Finding the runtime of a task by name

Can this query be improved? I iterate over a couple of thousand times, and if I can improve it, it should decrease the run time. Otherwise I might look into using a batch instead of doing one at a ...
1
vote
2answers
104 views

Weekly fee calculation

I have the following query. Its execution took 15 min and it's too much slow. Is there a way to optimize it? ...
7
votes
3answers
246 views

Normalizing Invoices

I need to move data from one database to another, and since I don't have SSIS I'm doing this ETL with T-SQL scripts. One of the source tables contains invoice details, and features a column that ...
3
votes
2answers
95 views

Role-based access control query

I use SQL Server, and though not pertinent here, Railo's CFML engine. I'm not great at SQL Joins, but I worked through this one and got the result set that I want. This particular SQL will only ever ...
0
votes
2answers
159 views

Optimize query containing too many inner join and rows

I have the following query: ...
6
votes
2answers
149 views

Follow up to Top Active Answerers on Stack Exchange site

This is a follow up to Top Active Answerers on a Stack Exchange site Actual SEDE Query --> Top Active Answerers on site Do I have a good understanding of the ...
3
votes
2answers
268 views

Top Active Answerers on a Stack Exchange site

I created this query back in January to find the top active answerers on Code Review and thought that it might be a good idea to get other opinions on my SQL coding using a database that we can all ...
3
votes
1answer
27 views

SQL update statement

I have a SQL update statement which does what it's supposed to. However, I have a feeling that the way I wrote it isn't the best. I am not highly experienced in SQL so any pointers or hints on how can ...
2
votes
3answers
213 views

Rewriting SQL IN statement with long list of parameters

These IDs seem like they should be a table as, there are several queries that use the same list of IDs. The following needs to be refactored. ...
7
votes
2answers
91 views

Query for your Answer Progress

I was inspired to write a query that produced a graph mapping the perceived quality of your Stack Exchange answers over time.... in other words, "Are your answers getting better, or worse?" Because ...
3
votes
1answer
34 views

Basic T-SQL to compare two same length strings

I've come up with the following T-SQL to compare similar same length strings. Example usage would be: OCR returns a value which is expected to be in the database. PATINDEX is used to check the ...
3
votes
1answer
66 views

Query for combining two SELECTs to get active users and 1 inactive user

What this query does: Gets multiple users with the first select in the union; those are the active users. But when a user is ...
2
votes
1answer
22 views

Optimizing sales report stored procedure

I need to optimize the following stored proc. Please let me know of any techniques or modifications that I can make to optimize this piece of code. The procedure is for a report that needs to run ...
5
votes
2answers
79 views

DateTime internal representation to FILETIME

Here is a routine I put together to convert SQL Server's internal DateTime representation (BINARY(8)) to a ...
1
vote
1answer
31 views

Too many parentheses to format a percentage in SELECT

This query seems to have way too many parentheses. ...
3
votes
1answer
55 views

Monthly change query with SQL Server 2012

I'm new to SQL and working on a monthly change calculation. I want to calculate the change between this months balance and the previous months balance. This query is working for me but does not ...
3
votes
2answers
99 views

Similar statements need duplication removed

How would you refactor this? ExpensiveQuery must only run when necessary. ...
4
votes
1answer
71 views

Unduplicated counts over various dimensions

I'm working with some data on college students, which has a unique key of SSN, Campus, ...
3
votes
3answers
273 views

Get and display employee time clock data

I have been making a web page in PHP and JavaScript to take employees clock times and do some things with them so I can display them. Everything is currently working quite well, but the code looks ...
6
votes
5answers
424 views

Transaction handling for multiple SQL statements

In this code I update two tables called Payment and SalaryTrans. First I insert records (Salary payments) to ...
5
votes
3answers
194 views

Legacy Data and Current System Data Merged together in a single SQL Database

There was a lot going on in this Database that I couldn't change, a lot of bad practices because the data was originally being pulled from an old mainframe database and then transformed by a horrible ...
3
votes
2answers
128 views

Efficient way to extract the first row in a Group By group

I have a large Sql Server view with this schema: [archive_ID] (int, not null) [archive_date] (datetime, not null) [archdata_path_ID] (varchar(50), not null) [archdata_value] (int not null) I need ...
5
votes
3answers
94 views

Relational schema and query for multiplayer tabletop game

As an exercise, I was asked to design a database schema (for MS SQL Server) for a tabletop game. The requirements were simple: players compete in matches and there are specific match types (e.g. 1v1 ...
2
votes
1answer
32 views

Reusing select statement

I am checking if there are any rows in a table with some conditions. If there are more than 1 row, it should filter again with some more conditions. ...
3
votes
1answer
36 views

Optimize mass import of XML to SQLServer in Ruby

I have the following Ruby code that's designed to update item, price and stock data for items in a MSSQL database. It's running on a Ruby 1.8.6/Rails 1.2.3 installation, in its own controller (for ...
4
votes
2answers
223 views

SQL percentage calculation

I have created a query in which there is a column that calculates a percentage: ...
4
votes
1answer
102 views

Batch of SQL statements in a single query

I'm using the following query for multiple transactions. This is the scenario. Generate Salary (this is not in the scope of the query) I have employee attendance in ...
6
votes
2answers
266 views

Multiple SQL statements in a single transaction

Using the following query I'm doing transactions with two tables ...
4
votes
2answers
124 views

Delete from multiple tables using temp table variable

I'm previewing the data I'm about to delete, but this SQL looks a little redundant. Is there a better way to write this? ...
17
votes
1answer
212 views

Executing large SQL script file with GO statements using ADO

I wrote a small component (still in the works but working) which takes a large SQL script file, splits it into different "blocks" based on GO statements, and executes them one by one. The only major ...
2
votes
1answer
124 views

Is there better way to shorten this Lambda expression's result selector?

I'm new in LINQ and Lambda expression. I'm not sure is there a way to shorten the result on this o.z.cust.cust.cust.bintAccountNo. As you can see below, the more ...
6
votes
3answers
89 views

SQL Stored Procedure Get Distinct and Update

The idea is to show how many times a user (by EmployeeID) is in the TblTableList and then update the ...
12
votes
2answers
341 views

FizzBuzz in SQL--no loops

MS SQL Server, no loops. ;) ...
6
votes
3answers
112 views

Sorting three Decimal values

I have been given three values. @lLength, @lWidth, @lHeight. I need to take these ...
10
votes
1answer
78 views

Loading Data Warehouse with Dynamic SQL

For a data warehousing project I ran into the following: Custom fields that users can create, modify and delete, that should be loaded into the data warehouse as they are when the ETL happens. On ...
3
votes
1answer
39 views

Printing simple SQL comparsion

I'm comparing two variables which I'd like to be printed to the console like so: ==Full Ex Vat== true Currently the code to do this is: ...
2
votes
2answers
46 views

Using Common Table Expression and Outer queries

In following query I'm use both Common Table Expression and Outer queries. Apparently both looks same to me. If I summarize my requirement, I have employees in ...
5
votes
2answers
67 views

Better way of calculating a time in a time zone from multiple dates in SQL?

I'm trying to calculate what time a certain time in a time zone is today, so I can schedule something to happen at that time in that time zone. I've got a table with what I have termed the Nominal ...
10
votes
3answers
335 views

Is there any way to speed up this stored procedure?

Is there any way to optimize this stored procedure? Maybe something instead of so many joins? It takes some time to execute. Maybe there are other options that I could look into? ...
5
votes
1answer
63 views

EF query for calculating monthly trends

My application has a fairly important query that is used in a lot of places. Unfortunately it takes about 14 seconds to run, so I'd like to find a way of possibly improving it. The application ...
11
votes
2answers
305 views

Find records with duplicate serial number

I was tasked today with cleaning up data from a SSRS report put together by a DB programmer. The original report was to find duplicate serial number sales within a user-defined period of time. I was ...
2
votes
1answer
307 views
7
votes
1answer
278 views

Fluent Nhibernate, is the mapping correct?

I'm very new to NHibernate and DB. I have three tables which are connected with many to many relationship. Here are the tables creation Script: ...