I am trying to update a table to set the Dup_Flag column equal to 'Y' when the Dup1 value is negative.
I think I need to specify this condition on a Qualify clause but I don't know how to write it. Hoping to get some help here.
I am using Teradata SQL Assistant version 17.10.03.22
This is my code:
UPDATE Table1
FROM
(
SELECT
"Date",
Call_GUID,
DeDup_CID,
Initial_Call_Time,
Final_Call_Time,
(Initial_Call_Time) - MIN (Final_Call_Time) OVER (
PARTITION BY DeDup_CID,
"Date"
ORDER BY Initial_Call_Time ASC
ROWS BETWEEN 1 PRECEDING
AND 1 PRECEDING) DAY(4) TO SECOND AS Dup1
FROM Table1
QUALIFY Dup1 < 0
)AS a
SET Dup_Flag = 'Y'
WHERE Table1."Date" = a."Date"
AND Table1.Call_GUID = a.Call_GUID
AND Table1.Initial_Call_Time = a.Initial_Call_Time
AND Table1.Final_Call_Time = a.Final_Call_Time
When I run this code, I get error message: Failed 5407. Invalid operation for DateTime or Interval.
This is how the data that results from the nested 'select' statement looks like:
Date | Call_GUID | DeDup_CID | Initial_Call_Time | Final_Call_Time | Dup1 |
---|---|---|---|---|---|
09/21/2023 | 4B7FF52 | 2140000000 | 09/21/2023 08:01:17 | 09/21/2023 08:04:00 | ? |
09/21/2023 | A174742 | 2140000000 | 09/21/2023 08:03:33 | 09/21/2023 08:04:01 | -0 00:00:26.180000 |
09/21/2023 | C174756 | 2140000000 | 09/21/2023 08:18:28 | 09/21/2023 08:19:02 | 0 00:14:27.074000 |
This is what I am expecting to get from the 'qualify' statement:
Date | Call_GUID | DeDup_CID | Initial_Call_Time | Final_Call_Time | Dup1 |
---|---|---|---|---|---|
09/21/2023 | A174742 | 2140000000 | 09/21/2023 08:03:33 | 09/21/2023 08:04:01 | -0 00:00:26.180000 |