-- dbo.ef_DilecGetStroj
CREATE FUNCTION dbo.ef_DilecGetStroj (@IDKmen INT=NULL, @NazevOp NVARCHAR(100)=NULL)
  RETURNS INT
AS
BEGIN

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

 DECLARE
  @retVal INT=NULL
 
 IF (@IDKmen IS NULL)
  RETURN @retVal
 SET @NazevOp = ISNULL(@NazevOp, N'')


 IF (@NazevOp<>N'')
   BEGIN
    IF 1=(SELECT COUNT(ID) FROM dbo.TabPostup WHERE Dilec=@IDKmen AND ZmenaDo IS NULL AND IDStroje IS NOT NULL AND Nazev LIKE @NazevOp + N'%')
     SELECT @retVal=IDStroje FROM dbo.TabPostup WHERE Dilec=@IDKmen AND ZmenaDo IS NULL AND IDStroje IS NOT NULL AND Nazev LIKE @NazevOp + N'%'
   END
  ELSE
   BEGIN
    IF 1=(SELECT COUNT(ID) FROM dbo.TabPostup WHERE Dilec=@IDKmen AND ZmenaDo IS NULL AND IDStroje IS NOT NULL)
     SELECT @retVal=IDStroje FROM dbo.TabPostup WHERE Dilec=@IDKmen AND ZmenaDo IS NULL AND IDStroje IS NOT NULL
   END

 RETURN @retVal
 
END
