Skip to content

Tag: tsql

Date cycle in T-SQL

I need to write a query that displays time intervals that go on without interruption. Example: Input: Output: I think we need to use the function DATEDIFF line by line. The problem is that I don’t know how to access indexes. Or can this problem be solved much easier? Answer This is a type of gaps-and-islands …

How to insert the result in the desired row? SQL Server

I need the result that I got to be inserted in the right row. That is, instead of WHERE id_prod = 1, there was something that inserted the desired result in all rows. I’m not sure I made myself clear, but I hope that you will understand. Answer I think you want There is no need to use a variable