-- dbo.ef_GetDatumASmenu
CREATE FUNCTION dbo.ef_GetDatumASmenu (@Datum DATETIME)
  RETURNS @retTab TABLE (Datum DATE, Smena TINYINT)
AS
BEGIN

-- !! funkci neupravujte, bude stejne pregenerovana pri startu pluginu PluginHDCRTN !!

 DECLARE
  @hod TINYINT,
  @lDatum DATE,
  @smena SMALLINT
 
 SET @lDatum = @Datum
 SET @hod = DATEPART(hour, @Datum)
 SET @smena = IIF(@hod BETWEEN 0 AND 5, -1, IIF(@hod BETWEEN 6 AND 13, 1, IIF(@hod BETWEEN 14 AND 21, 2, 3)))
 IF (@smena=-1)
  BEGIN
   SET @smena = 3
   SET @lDatum = DATEADD(day, -1, @Datum)
  END
 INSERT @retTab SELECT @lDatum, @smena
 RETURN
 
END
