Skip to content

How to make LAG() ignore NULLS in SQL Server?

Does anyone know how to replace nulls in a column with a string until it hits a new string then that string replaces all null values below it? I have a column that looks like this Original Column: …

Count number of items per ID

I have a table as below INPUT ID ITEM 1 Apple 1 Banana 1 Orange 2 Pear 3 Apple 3 Pear I want to count the items per id, such as OUTPUT ID ITEM ITEMS_PER_ID 1 …

Query returned values in SQL

I would like to write an SQL query which uses results from previous one. For example – I have a table Orders with fields: order_id, date and value. I need to get all dates from column date where …

Join Generated Date Sequence

Currently I’m trying to join a date table to a ledger table so I can fill the gaps of the ledger table whenever there are no transactions in certain instances (e.g. there are transactions on March 1st …