I have a field in our jobs table in the ERP system which gets updated by a stored procedure when the job record has been transmitted to our supplier by FTP. However, I have noticed that it is not always setting the time element correctly. It does so sometimes, but not every time. The date part is always being set, but the time element is needed so we can report on the suppliers SLA performance.
This is the stored procedure, which receives the record key of the job and then updates the Transmitted field (datetime) in the ERP jobs table. The transmission of jobs only happens in business hours - between 07.00 and 18.00 daily:
CREATE PROCEDURE [dbo].[FTPSuccess]
@reckey VARCHAR(10)
AS
-- SET TRANSMITTED FLAG ON JOB
BEGIN
UPDATE JobHdrProfiles
SET TRANSMITTED = CAST(GETDATE() AS DATETIME)
WHERE RECKEY = @reckey
END
And here is a sample of the results from 22/03/2023, as you can see while they were all dated correctly, some of them have the time element showing as 00:00:00.000:
+------------+-------------------------+
| RECKEY | TRANSMITTED |
+------------+-------------------------+
| 5001005413 | 2023-03-22 00:00:00.000 |
| 5001005424 | 2023-03-22 00:00:00.000 |
| 5001005458 | 2023-03-22 13:42:04.507 |
| 5001005462 | 2023-03-22 13:42:04.507 |
| 5001005467 | 2023-03-22 00:00:00.000 |
| 5001005478 | 2023-03-22 00:00:00.000 |
| 5001005490 | 2023-03-22 14:00:05.063 |
| 5001005493 | 2023-03-22 14:20:06.383 |
| 5001005513 | 2023-03-22 00:00:00.000 |
| 5001005518 | 2023-03-22 14:18:03.457 |
| 5001005519 | 2023-03-22 00:00:00.000 |
| 5001005527 | 2023-03-22 14:54:03.113 |
| 5001005533 | 2023-03-22 00:00:00.000 |
+------------+-------------------------+
Why would this be happening? And what can I do to correct it - I cannot change the field type in the ERP system?
Many thanks
Martyn