How to remove duplicate dates in sql?

0

Good morning, I need some help for the following problem, I have this code

Whichgivesmethefollowingresult,howeverIwouldliketoremovetheduplicatedates

Thanks in advance.

    
asked by anonymous 08.08.2017 / 13:22

2 answers

1

Hello, I also see as a problem the name of the database being "Master", not a good practice, but it is possible.

On the SELECT table, the LFU_Float and Equip_String tables are not used but are in the FROM clause. And the TDL_Float and TLI_Float tables are not bound by a key     

14.08.2017 / 19:14
-1

What I noticed is that there are no repeated lines, but rather that the type of junction used was Cartesian product, which gave the impression that there were repeated lines. Also, in the FROM clause there are tables that are not used in the query, such as LFU_Float and Equip_String.

The tables are in the master database, which is a SQL Server control database. If possible create a specific database to store the tables.

The problem is restricted to performing the marriage between a shutdown and its reclosing, which are recorded in different tables. There are a few ways to solve what you need.

Here's a solution:

-- código #1 v2
declare @DATAI1 datetime, @DATAF1 datetime;
set @DATAI1= convert(datetime, '7/8/2017 7:00', 103);
set @DATAF1= convert(datetime, '8/8/2017 6:59:59.997', 103);

with OffOn as (
SELECT TDL.DateAndTime as Deslig,
       (SELECT top (1) TLI.DateAndTime
          from TLI_Float as TLI
          where TLI.DateAndTime > TDL.DateAndTime
                and TLI.Val <> 0
          order by TLI.DateAndTime) as Relig
  from TDL_Float as TDL
  where TDL.DateAndTime between @DATAI1 and @DATAF1
        and TDL.Val <> 0
) 
SELECT Deslig as [Desligado às],
       Relig as [Religado às],
       cast( dateadd(second, datediff(second, Deslig, Relig), 0) as time(0)) as [Tempo parado]
  from OffOn
  order by Deslig;

The above solution assumes that for every logged-off, there is always a recloser registered and the shutdown interval never reaches 24 hours or more.

    
08.08.2017 / 14:23