Good day, I have a problem regarding MySQL queries. I want to create a daily time record output but my problem is on making queries. What I want is that when a record have the same id and date it must be updated otherwise it will insert a new record. These are some of screenshots of table properties
CREATE PROCEDURE dbo.EditGrade
@Id int
,@TimeIn datetime
,@TimeOut datetime
,@Existing bit OUTPUT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @CurrentTimeIn as datetime
DECLARE @CurrentId as int
SELECT @CurrentId = Id
FROM tblAttendance
WHERE TimeIn = @TimeIn
IF (@CurrentId <> @Id)
BEGIN
IF (SELECT COUNT(ISNULL(Id,0))
FROM tblAttendance
WHERE TimeIn = @TimeIn
SET @Existing = 0
ELSE
SET @Existing = 1
END
ELSE
BEGIN
SET @Existing = 0
END
IF @Name = ''
SET @Name = null
IF (@Existing = 0)
UPDATE tblAttendance
SET TimeIn = @TimeIn
--other column values here
WHERE Id = @Id
ELSE
--INSERT FROM tblAttendance query here
END
GO
this is from stored procedure of ms sql, you can just convert it into mysql version.
take note, datetime types also checks the seconds, so don't include the seconds as much as possible or it will render as NOT THE SAME (eg time in = 10:00:01 and time out is 10:00:02 will be rendered as NOT THE SAME)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.