Skip to content

SQL Subtract from different tables

I’m subtracting values from diferent tables based on ID. Its like an inventory where I’ve the tables for Itens In and Itens Out. What I want to do is to substract the Itens In – Itens Out based on ID …

Looping in SQL with TempTable

I am new to SQL Server, can you please help me to write query for my scenario? I have this Table1 : Input to my stored procedure is a PolicyNumber e.g 1234 and the code should return 5 rows. I need to cover these cases: If the first payment is not cancelled, I need return that row. If the first

default rows from select query

I have a select query (Oracle database) with group by clause that needs to return 4 rows if all required data exist. It works perfectly. How can I write a select query that returns same 4 rows even if …