Skip to content
Advertisement

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 problem. Use a lag()

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

Create a View in SQL with a Concatenated Column > Then use Case Statement to affect values

I created a view with a concatenated column named DisplayName, using the code below. Is there a way to change specific DisplayName values using a case statement (or a better method) Something like: case when DisplayName = ‘Robert Jones’ THEN ‘Bob Jones’ when DisplayName = ‘Thomas Simms’ THEN ‘Tommy Simms’ or when FirstName = ‘Robert’ AND LastName = ‘Jones’ THEN

Advertisement