Skip to content

Tag: sql-server

How to group this table properly?

Here’s my dataset with expected out. But I am having issues doing it. Also, I attached the query I created and the output is not correct. could you please point me to where my mistake is? DROP TABLE …

SQL window function with date filter

Looking to do a LAG/LAST_VALUE/MAGIC window function on a table which somehow needs to include a date filter (as in how far back it should go). I’m trying to get the value as of 7 days ago onto every …

SQL query not showing the right result when using LIKE

I am using Microsoft SQL Server Management Studio 2018 for my queries and I am trying to get the total quantity of ‘Cavity’ part types for each order and I have notice some anomaly for 1 order. I am 99% sure that it has been properly added to the SQL database as each order is first created in Acce…

SQL Server : select first occurrence from two columns

(Edit: I am bound to use Visual Studio 19 and have no rights to install any other application) I have a small SQL table with about 150k rows and 20 columns which I need to modify. I need the table to be ordered by date. I need the first occurrence of a value from two columns. Depending on if the