Skip to main content

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

Filter by
Sorted by
Tagged with
4 votes
1 answer
74 views

I've got the following SQL that I need to update by adding a new parameter: ...
jp2code's user avatar
  • 328
1 vote
1 answer
50 views

dbfiddle Goal Without repetition in the code, I want to filter BikeValuationList to only give the BikePriceId of the latest ...
J. Mini's user avatar
  • 137
3 votes
2 answers
137 views

I have a transaction table let's call it Offers Table. Please don't read too much into the business but let's say a customer wants to buy a car and the customer searches variety of websites but at the ...
Cody's user avatar
  • 31
2 votes
1 answer
76 views

This query selects the number of SO questions, the number of views and the number of unanswered questions for each tag (the list of the tags is the user input). It works fine when it works, but it ...
Yulia V's user avatar
  • 645
3 votes
1 answer
111 views

Context I was proud of this code for a little while, but the repetition wounds me. I know that the function name sucks, but the name and interface to this function are not under my control. ...
J. Mini's user avatar
  • 137
2 votes
2 answers
144 views

Context I was proud of this code for a little while, but the repetition wounds me. I know that the function name sucks, but the name and interface to this function are not under my control. ...
J. Mini's user avatar
  • 137
1 vote
1 answer
174 views

The Question What is the percentage of customers who increase their closing balance by more than 5%? Source Code The database and all details can be found here. ERD My Proposed Solution ...
Mike's user avatar
  • 113
0 votes
1 answer
138 views

I have this stored Procedure that is passed in the data below that will building the SQL select that will get EXEC. The data that can be passed in can me null so I have three ...
Jefferson's user avatar
  • 423
1 vote
1 answer
93 views

I'm playing with data from a Time Use survey as a beginner SQL user. Gender is represented as 1's (Male) and 2's (Female), and the age of each participant is listed. I would like to divide them into ...
Erik's user avatar
  • 303
0 votes
1 answer
213 views

Given the following example data: id username group unit department team status 1 user1 g1 u1 d1 t1 active 2 user2 g1 u1 d1 t2 active 3 user3 g1 u1 d1 t3 inactive 4 user4 g3 u6 d12 t30 active 5 user5 ...
pileup's user avatar
  • 461
-2 votes
1 answer
92 views

I'm in need to optimize the following TRANSACT SQL statement : ...
Simone Spagna's user avatar
3 votes
0 answers
62 views

I am working on SQL Server I have sample data like this in a table. CustId Bank city rating date rnk 1 Deutsche Delhi 5 10/10/2022 1 1 BOA Pune 6 10/10/2022 2 1 UBS Mumbai 7 10/10/2022 3 1 SBI ...
user3580341's user avatar
0 votes
1 answer
80 views

I have transaction tables called MaterialRequest and MaterialRequestDetails. What I want to check my query and review that it's ...
Basit Sarguroh's user avatar
5 votes
0 answers
79 views

Today, I've got a small FlowLogger for you to review. The idea is not to log pure messages, but focus on the flow of the app that might contain such items as: <...
t3chb0t's user avatar
  • 44.7k
0 votes
1 answer
79 views

The problem I have solved is as follows: Consider a table of dogs, DOGGIES, that records on each row the ID of a doggy, one ...
J. Mini's user avatar
  • 137
-2 votes
1 answer
95 views

The query below already has indexes based its execution plan but it is still under performant with larger datasets. Are the additional null checks needed and why? Do you see anything that can be done ...
Rick B.'s user avatar
  • 135
3 votes
2 answers
181 views

I am not very experienced with T-SQL and feel this can be done better. The script changes ownership of all "user" (non-system) databases to sa. Usage of a ...
Igor Soloydenko's user avatar
2 votes
2 answers
92 views

We have recently migrated from SQL Server 2008 R2 to SQL Server 2017 web edition. I am not a SQL developer but enthuses to learn. Since many of our scrips are of old SQL format, I am searching for ...
Aditya Sawant's user avatar
4 votes
1 answer
234 views

The following SQL code serves the purpose of assessing basic SQL Server literacy. I am creating database and tables schemas, inserting data from .csv files. Constructing 8 simple queries as answers to ...
I. Я. Newb's user avatar
0 votes
1 answer
405 views

I have a set of tables that I want to execute a LEFT JOIN on and bring back "excluded" rows. In addition, I would like the left table's ID included as ...
akousmata's user avatar
  • 101
3 votes
2 answers
165 views

Currently with a given Date and an Interval in Day, I can calculate all of the appointment in the future. for example if you are ...
Masoud R's user avatar
3 votes
0 answers
50 views

I've created the following SEDE query which calculates the reputation averages of users on a particular site. It also optionally excludes "new" users (users with rep of 1 or 101 so note 100% ...
TheLethalCoder's user avatar
1 vote
1 answer
71 views

I build database called MessageBoard and created StoredProcedure GetHomeView that return data for HomeView. I am completely new ...
user221124's user avatar
5 votes
2 answers
822 views

I have a primary table, REP_ASSIST.ES_LOG with multiple columns that are foreign keys to another table, ...
Zephyr's user avatar
  • 217
4 votes
2 answers
222 views

I have SQL scripts that I want to be executable directly in the editor (like DataGrip or SSMS) and also in automated integration tests. However, in each use-case they require different environment and ...
t3chb0t's user avatar
  • 44.7k
3 votes
1 answer
108 views

The codes below get the rows of data until it reaches the total running quantity limit. Notice that the SQL uses sub-query. ...
h3n's user avatar
  • 133
1 vote
1 answer
54 views

I have a query I am writing where I want output if a person has some service provided, then I want all the services they had provided after that and I don't want the individual returned if that is the ...
MCP_infiltrator's user avatar
3 votes
1 answer
1k views

Below is a delete job to delete 1M+ records daily and takes 13 hours to complete and sometimes more than that. I need to optimize this. The table tblcalldatastore is being inserted 24*7 through a ...
Andy's user avatar
  • 43
12 votes
1 answer
338 views

Prompted by discussion about SQL injection, I wanted to put a proof of concept forward to get feedback about whether this is in fact safe and protected against SQL injection or other malicious use. ...
this's user avatar
  • 2,039
2 votes
2 answers
429 views

Here is a set of classes that are used to build where clause for SQL Server and Oracle for different field types e.g. text, <...
Aashish Upadhyay's user avatar
1 vote
2 answers
132 views

What I want is getting all names (first, middle, last) of the users along with each of their total hours of work which will be calculated by the SQL statement: ...
Gene Adrian San Luis's user avatar
1 vote
1 answer
123 views

QUESTION: Choose the name of clients, concluded more than one loan agreement in 2010, as the numbers and dates of issue of these contracts. Sort by name of the client and date of issue of the loan. ...
Pavel Kononenko's user avatar
3 votes
1 answer
61 views

Question: There is an Exam_Merge table into which to import records from a similarly structured table in another database. In this case, the Exam_Merge table contains the values of the primary key ID ...
Pavel Kononenko's user avatar
4 votes
1 answer
263 views

Calculate the number of loans issued by the Regional offices for each business week in the period from 38 to 40 business week of 2011 inclusive. Sort by name of the regional unit, business week. ...
Pavel Kononenko's user avatar
4 votes
1 answer
1k views

I want as an exercise to create an e-commerce application from bottom up. My main goal here is to gain a lot of knowledge. I have experience in web development, but never have been there from the ...
JeremyVm's user avatar
  • 143
1 vote
1 answer
108 views

I have written a query to generate payroll based on attendance for a month, for about 4000 employees. It takes quite a long time to execute. Basically, what I am doing is to joining two different ...
Parvez's user avatar
  • 23
1 vote
1 answer
675 views

I have a fairly complex query which insert multiple rows into a table from multiple tables. Its works fine but I really don't want to use cursor as some blog says cursor took long time for execution (...
Parvez's user avatar
  • 23
1 vote
1 answer
160 views

This is my code for my SqlDataAdapter which is similar to the code example given in the docs: ...
asathkum's user avatar
  • 245
3 votes
2 answers
810 views

Bit of a complicated one for me. I have a database full of hundreds of thousands of records, many of which are duplicated. I need to get all records within the last year but making sure every ...
Matthew Stott's user avatar
1 vote
1 answer
1k views

(We are on SQL Server 2008). The following constellation: Our applications passes date&time around (in the most horrible way possible). We want to simplify this. Instead of a culture-specific ...
Quandary's user avatar
  • 159
7 votes
1 answer
355 views

Business logic It would take us too far to explain the whole business case behind this code, so I'll try to be as succinct as possible. There are Persons, and ...
BCdotWEB's user avatar
  • 11.4k
4 votes
1 answer
137 views

One of the app is inserting date in UTC format (column CreateDate). When reporting from this table, I used a difference in hours between the inbuilt ...
Ashish Gupta's user avatar
2 votes
1 answer
457 views

I have a large table in which I store region/state/province codes (two letters) from different countries. I use these region codes further downstream for multiple process. One of the steps I do is a ...
VK_217's user avatar
  • 141
4 votes
1 answer
206 views

We ship large spools of copper wire and pallets of copper rod that have to meet specific chemical and mechanical requirements, this is what must be put on the certifications. I created an SP which ...
Mike's user avatar
  • 195
0 votes
1 answer
86 views

I need to run this script to update the value of 3 columns based on certain conditions. Right now, this is what I have: ...
João Pinto's user avatar
3 votes
1 answer
100 views

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 ...
RMSPereira's user avatar
3 votes
1 answer
1k views

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 ...
Owain Esau's user avatar
1 vote
1 answer
147 views

I'm currently using a stored procedure(sproc) to export to Excel. The sproc is being passed ...
Jaskier's user avatar
  • 111
1 vote
1 answer
305 views

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 ...
FreeMan's user avatar
  • 1,300
5 votes
1 answer
303 views

I've written a view to retrieve each product's sold quantity and four week sales average by Branch/Route/...
Shelby115's user avatar
  • 1,971

1
2 3 4 5