>>SELECT @count = count(*) FROM mytable >>WHERE fk=@fk AND >>YEAR(clock) = YEAR(@clock) AND >>MONTH(clock) = MONTH(@clock) AND >>DAY(clock) = DAY(@clock) >> >>IF @count<2 BEGIN >> // insert this is easy >>END ELSE BEGIN >> // find the correct @pk to update >>END >>>>
>SELECT @count = count(*), > @MinTime = MIN(DateTimeField), > @MaxTime = Max(DateTimeField), > FROM mytable >WHERE fk=@fk AND >YEAR(clock) = YEAR(@clock) AND >MONTH(clock) = MONTH(@clock) AND >DAY(clock) = DAY(@clock) > >IF @count<2 BEGIN > // insert this is easy >END ELSE BEGIN > IF @MinTime -- Here I am not sure what you mean with "if the passed clock is less than the min time for that day" > BEGIN > UPDATE ..... > WHERE fk=@fk AND > YEAR(clock) = YEAR(@clock) AND > MONTH(clock) = MONTH(@clock) AND > DAY(clock) = DAY(@clock) AND > DateTimeField = @MinTime > END > > IF @MaxTime -- Here I am not sure what you mean with "if the passed clock is greater than the min time for that day" > BEGIN > UPDATE ..... > WHERE fk=@fk AND > YEAR(clock) = YEAR(@clock) AND > MONTH(clock) = MONTH(@clock) AND > DAY(clock) = DAY(@clock) AND > DateTimeField = @MaxTime > END > >END >Good idea. I think the passed time is @clock variable.