Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [t-sql]

Transact-SQL (TSQL) is the extended SQL dialect used in Microsoft SQL Server and Sybase. Please also tag with either [sql-server] or [sybase].

0
votes
0answers
15 views

Retrieve sum of specific bitarray sequences

I have a table that has the following data: ...
1
vote
0answers
16 views

Loop Through bitarray to retrieve subsets of that bitarray

Objective: I want to loop through a bitarray and store subsets of that bitarray in a table. Context: I have a bitarray with 48 elements where each element represent one hour. I want to look back 24 ...
1
vote
1answer
77 views

Inserting data into SQL-Server table dynamically

I know I can do all this via SSMA quite quickly, but I wanted to see if I could do it efficiently in PowerShell myself as a little project. Basically, the entire script takes tables from an Access ...
0
votes
1answer
52 views

SQL Stored Procedure to export specified data

I'm currently using a stored procedure(sproc) to export to Excel. The sproc is being passed ...
1
vote
0answers
117 views

Stored procedure that adds row-level auditing to a table

I'm looking for any suggestions on how to improve my T-SQL for this procedure. It works okay, but I'd like to get advice to improve it from more experienced SQL developers. This procedure adds 4 ...
1
vote
1answer
53 views

Calculate NPS in a stored procedure

We collect customer surveys and one of the questions is the dreaded "How likely are you to recommend our service?" question from which we calculate a Net Promoter Score. (I hate this calculation, but ...
4
votes
1answer
86 views

Retrieving a product's sold quantity

I've written a view to retrieve each product's sold quantity and four week sales average by Branch/Route/...
6
votes
2answers
90 views

Find how much reputation a user had on a given date

I saw this question on MSE and went ahead and wrote a solution to it: https://meta.stackexchange.com/questions/313561/determining-users-reputation-as-of-particular-date This calculates the ...
6
votes
0answers
103 views

Modeling tabular structure in MSSQL to store data like Excel sheet applying Column inheritance

I've created this database structure to store tabular information (it's a simplification of my real structure but enough to show the point). In it I have Sheets and ...
4
votes
0answers
38 views

Insert a page definition in the right order

I have a table SlideList that defines all available slides that can be put into a PowerPoint presentation. I have a table ...
4
votes
2answers
65 views

Simple locale loader

I have a class that loads locales from a database. I'm not sure if locale is the right word. It's basically loading texts for a game, generic sayings like alerts and error messages. I'm also not sure ...
1
vote
1answer
46 views

Simple script to insert data

This is a simple script which inserts data into a couple of tables. I'm very new to SQL so any feeback, of any kind, would be much appreciated! ...
1
vote
2answers
67 views

Merge table stored procedure

I wrote a stored procedure that will do a merge of two tables: ...
3
votes
2answers
76 views

SQL Server - Iterate, aggregate, and insert

I'm trying to find an efficient way to aggregate data for reporting. Let's say I need to aggregate the following data in 5-second intervals: ...
4
votes
1answer
30 views

Parse numbers from text based on relative position to certain substrings

The input is a product code. I want to pull out the "percentage" portion of that code. For example, if the code contains the substring BIO, I want all the numbers that follow it until I hit another ...
2
votes
1answer
55 views

SQL Query to check if 100+ (or Dynamic) columns in table is null

Let assume a table has more than 100 of columns & I want to display all the rows when all of its columns (Col1, Col2, ..., ColN) are nulls except for the column(s) I mentioned (PK). This is just ...
0
votes
1answer
43 views

Query to show each sites stock transfer history between all other sites

The below query is used to return a dataset for a SSRS report. It works fine and is quick enough but I am looking for any improvements that could be made. The client has asked to see all transfers ...
1
vote
2answers
54 views

Displaying a single record based on DocID

I have a table with ~900,000 records. I need to display a single record based on DocID using this query. The record is the latest record that got modified by another program. This piece of query run ~...
5
votes
0answers
50 views

The seasoned Zombie sniper: a query to find unanswered questions with specific tags

The query (on SEDE) This query builds upon the previous and includes the suggestions by rofl as well as the now mentioned activity index. ...
11
votes
1answer
83 views

The sniper: a Zombie searcher for specific tags

Sometimes, it's not enough to know what the easy prey is. You also need to know whether you will be able to hunt it down. What good is an almost turned haskell zombie if you cannot read the functional ...
13
votes
1answer
1k views

A wounded Zombie finder, or: how to find the almost dead undead?

The Zombies are on their way to eat our statistics. Fortunately, we have a way to get rid of them: our votes. However, we need to find them first. The /unanswered section is too large and contains ...
2
votes
3answers
73 views

search for text across multiple tables

I've got the following query. ...
0
votes
1answer
60 views

T-SQL query outer apply with nested subqueries

I have the following 3 tables, and I don't have the option to modify them. [Logs] table with [log_type], ...
2
votes
2answers
90 views

T-SQL simplify repeated query unions for each day of the week

I've created the T-SQL code below to get the next nearest datetime value during the next 7 days. The ScheduleDetail table schema is: ...
1
vote
1answer
45 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
85 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. ...
2
votes
1answer
148 views

Report which connects to SQL Server via ODBC

I've created a report in Excel which connects to SQL Server via ODBC and I wrote some VBA to allow parameters to be passed in optionally. At this point everything works as expected but I'm curious to ...
1
vote
0answers
45 views

Creating SQL Indexes on Large Tables

I currently have a table with about 29 million records. The table currently has no indexes. However, I would like to build a composite index built on three columns. When I attempt to add the NON ...
8
votes
3answers
563 views

SQL trigger to log when employee records are updated

I am learning TSQL (SQL in general for that matter), and I wrote this trigger that inserts logs about updated employees into the tblEmployeeAudit table. When I was ...
1
vote
2answers
49 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 ...
1
vote
1answer
31 views

T-SQL Trigger Updating another table - Baseball Database

This is my first time writing T-SQL so I'd like to get some criticism on how I wrote this trigger. I'm building a Pitch-Tracking App that will use a relational database to track Pitches, At-Bats, ...
-1
votes
3answers
70 views

Insert to table from a temporary table [closed]

I created a procedure involving dynamically collecting from various projects (databases) some records into a temporary table and from that temporary table I am inserting into a table. With a ...
1
vote
1answer
221 views

Alternative to XML PATH

This inserts into 3 tables really quickly. My SELECT at the bottom appears to take an age, I assumed it would be fairly quick but is not. Is the XML path the right ...
3
votes
1answer
101 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 ...
1
vote
1answer
54 views

Posts that probably need editing

I wrote this Data Explorer query (reproduced below) some time ago that helped identify posts containing potential spelling/punctuation errors and earned me a Copy Editor badge on Anime.SE. ...
3
votes
1answer
278 views

Small DSL: Converting JSON to MSSQL query

Scenario Once upon a time, there was this human (ahem, me, ahem) who tried (and succeeded) to build a small program which would convert JSON to a MSSQL query using Python 3.x. How does it work? The ...
2
votes
2answers
70 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 ...
1
vote
0answers
37 views

Check status of all child generations of medical claim

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 ...
1
vote
1answer
42 views

Remove table variable from query

I am running this query, and to get the calculation that I need, I use a table value parameter to house some of the data. Scanning roughly 50K rows to create the table value parameter then performing ...
0
votes
1answer
43 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....
3
votes
2answers
55 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
78 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 ...
1
vote
1answer
119 views

Schema for SQL database of guitars

I just want to ask you guys if the database design that i made for my asp.net website is correct or not. So basically, I created a database for the brands of my guitar products, which is like this: ...
1
vote
1answer
63 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: ...
2
votes
1answer
106 views

Optimising performance of long running a sql query

The code below takes 5-6 hours for a years worth of data (850,000 records). It takes much less time when running a single month. To start with is there anything glaringly obvious within this script ...
2
votes
2answers
58 views

Find occurrences of strings in view B in column from table A

I'm trying to find the occurrences of strings in view B in a string in table A. However, the performance is horrendous (takes about 17 minutes to run) and I was wondering if anyone had any suggestions ...
3
votes
0answers
99 views

SqlServer database reflection and autogenerating NLog.xml

This is my first attempt at using T4 templates and I thought I generate the NLog.xml with it by getting the tables and the columns from the database to ...
1
vote
1answer
32 views

Extract Students with All Enrolments in the Past

I am trying to extract the students where all of their enrolments are in the Past. Some students can have more than one Enrolment and one of its End Date is in the future while the other one is in ...
3
votes
1answer
62 views

Kill All Connections For Domain Account Users

I have an application that has hundreds of users. Every now and again we need all users out of the application to run apply a fix on the data in DB (edit tables, causing triggers to be disabled during ...
5
votes
2answers
41 views

Query that shows similar columns between different tables on a database

In my work, I often have to take a naive look at tables and then never see them again, and it can be difficult to see what lines up where for large databases with many columns. I wrote this, and while ...