Let’s say I have data that looks like this: I have some records that are retired and some that are active. The problem is some of my records have both retired and active rows. I only want records that do not have an active row. So in this example despite the fact that Greg has 2 retired rows. The fact
Tag: sql
How to update one row that has max value in column (SQL Server)
I am trying to update the Rows that have the Max score with the value of ‘Yes’ in the Text1 column. This is straightforward except when there are multiple rows with the max score. If they have the same score, I just want to select the top row to have the value ‘Yes’. Only one row with …
SQL Server : fastest way to change rows to columns
I’ve got an issue regarding two tables in my database that have the following columns: COMMENT table Composite key made up of (KEY, TYPE, NUMBER) RESULTS table An example of the COMMENT table would be this: For each KEY, there are only 3 different types A,B,C and one TYPE may have up to 0020 in the NUMB…
Repeating rows but changing column value each time
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
SQL GROUP BY and COUNT with multiple columns
I know I’m just making a simple error somewhere, but I can’t figure it out. I’m sure this is beyond easy. I have a table with user ids, names, and a profile. I’m trying to count the number of users with each profile, and group them by the profile. Below is a sample of fake data. This i…
MySQL keyword aliases
I would like to set up aliases for MySQL keywords for faster typing of repetitive (or any, really) queries. Example: -> becomes: How could I go about achieving the above? I have looked around but unfortunately, most searches point to column and table aliases and I did not see a mention in MySQL documentati…
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
Alter Table Auto Increment starting number criteria from another query or field
I have a database that stores all our distribution partner sales. Every week I get updated sales that I load into what I call tblImport. I then have some queries I run that parse out new sales lines to tblUpdate and tblNewAccounts. What I am struggling with is automating what I call the Bill To ID(BT_ID) fiel…
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:
Convert html foreach loop data to webgrid using asp.net mvc
Below html table is filling using two loop condition, and same i want using two loop conditions to fill Webgrid I have tried to fill one field in web grid by using below code. when I am click debugging mode after code line complete on this line the following error is showing. Answer The exceptions you’v…