I need help to SUM and MULTIPLIES on join 2 tables: tb1 tb2 In tb1, I need to sum QTY and multiples SKU with PRICE without repeating same SKU (21135208, 21035621): Current query: My result is: Expected result is: Answer I believe that you could filter out duplicates by using a subquery like SELECT DISTINCT … FROM tb1, while leaving
Tag: tsql
How to Filter multiple values for Where statement of SQL
Can any help on the below Query in the where statement in T-SQL? I have ID & Product fields in table,in where condition need to exclude the ID not in(’11’,’22’,’33’) only when for Product=’c’ …
Extract a specific value from a string in a column
Need help with a situation, I need to extract a specific value from a column containing string. The string varies over different records, but the value I need to extract is always preceded by the word “VERSION” I tried to user REVERSE & SUBSTRING but not able to get exact results. Any help will be greatly appreciated the table looks
SQL server: How to Modify a JSON element value in a nested JSON array
If i have below JSON (@CarDataJsontest) e.g { “house”: { “gate”: [ “Car1”, “Car911”, “Car3”, “Car4” ] } } If i need to do is to modify the car911 to car2 all i …
Extract only dates for first Day of Month from a daily Date Dimension Table without nesting
I am using SQL Server 2014 and I have the following T-SQL query which retrieves the dates of the first day of each month (based on my filters) from a Date Dimension Table: SELECT * FROM ( SELECT …
datediff for row that meets my condition only once per row
I want to do a datediff between 2 dates on different rows only if the rows have a condition. my table looks like the following, with additional columns (like guid) Id | CreateDateAndTime | …
Selecting all foreign rows for each row useing a N-N table
I have a N-N table, lets say as an example Teachers and Subjects: There is a Teacher table as follows: There is a Subject table as follows: And there is a TeacherTeachesSubject as follows: Only that each table has more than 10000 entries. I need to make a query which returns me something like this: What I am doing right
How to pull week ending dates and end of month when end of month is mid week
I’m unsure how to proceed with this or what to search for but here goes my attempt at explaining what I’m trying to do! There may be multiple ways to figure this out as well. I am working on a …
Dynamically name a column based on a WHERE condition
Objective: I am running a query on a weekly basis and would like one of my column to return the ISO_WEEK number with the prefix ‘W’. For example: W1. More specifically, I would like to reproduce the …
Recursively calculate product weights in product tree
I’m developing a software for Consumer price index calculation and one step of all calculation is to calculate product weights in product category. This should be done in SQL server side. I have MS …