I’ve this table with the following data: ID Quantity Status 1 250 OK 2 440 HOLD 3 180 HOLD 4 860 OK Based on the value in the Quantity column for each row, the row should be repeated again if Quantity is bigger than 200, but repeated
Tag: sql-server
Provide a list of subtypes from Main group with range numbers
I have a table named Items containing a list of items both at grouped level (G) and sub level (L). However I want to see only the sub level (L) data but with the respective Group Name attached to each sublevel. The Grouped item has a start and end number range. The numbers are not +1 for the sub level
How to find records with over a set amount over a 5 year period
I’m trying to find contact_numbers in a financial table who have given over 5000 in any 5 year period since 01/01/2011. I’m going around in circles. This is what I have but it’s calculating everything from 2011. Any help would be great! Answer I think you want this structured as:
Want the count how many times row changes from -1 to 1 or vice-versa in SQL Server
SQL query to display the count, how many times row changes from -1 to 1 or vice-versa in SQL Server in a table. Let the table name be A Answer For this question to have an answer, you need a column that specifies the ordering. SQL tables represent unordered (multi)sets. There is no inherent ordering. To answe…
SQL Server 2014 slow remote insert
I have several linked servers and I want insert a value into each of those linked servers. On first try executing, I’ve waited too long for the INSERT using CURSOR. It’s done for about 17 hours. But I’m curious for those INSERT queries, and I checked a single line of my INSERT query using Di…
How to split string with delimiter and get the first value
I have the following query where I have a table which is storing from information with a delimiter SQL version – Microsoft SQL Azure (RTM) – 12.0.2000.8 Getting the following results Where I need the results to be Answer If you only interested in the first value, you don’t need to use STRING…
How to add a query to a table in SQL?
I have 3 tables. For simplicity I changed them to these sample tables. table1: CorporateActionSmmary table2# ProductMaster table3# OpenPosition First I need to add ISIN from table2 to table1 table1: CorporateActionSmmary So, I used this code Now as you can see the Quantity is missing in Table1 so I have to ad…
Filter rows of a table based on a condition that implies: 1) value of a field within a range 2) id of the business and 3) date?
I want to filter a TableA, taking into account only those rows whose “TotalInvoice” field is within the minimum and maximum values expressed in a ViewB, based on month and year values and RepairShopId (the sample data only has one RepairShopId, but all the data has multiple IDs). In the view I hav…
How to avoid rerunning a subquery used multiple times?
The following is a simplified example of a problem I’m running into. Assume I have a query “SomeQuery” (SELECT… FROM… WHERE…) that gives an output that looks like this: Status MyDate A 6/14/2021 A 6/12/2021 B 6/10/2021 A 6/8/2021 B 6/6/2021 A 6/4/2021 I need to get the earl…
For each product get the second customer who made a purchase
Given a table: Question: For each product get the second customer who made a purchase The following query Gives the result: And the expect result is: Here is the script to create a table: Answer You need to pair down the customers first so there is only one record per customer: