
IF OBJECT_ID('dbo.fnGetHetNapja') IS NOT NULL BEGIN
  DROP FUNCTION dbo.fnGetHetNapja
END
GO

CREATE FUNCTION dbo.fnGetHetNapja (@date datetime)
  RETURNS int
BEGIN  
  DECLARE @value INT
  
  SELECT @value = MIN(ID) 
  FROM T_DICTIONARYITEMBASE d 
  WHERE d.C_TYPE = 'HetNapjaTipus' 
    AND d.C_VALUE = (DATEPART(dw, @date) + 1)
  
  RETURN @value  
END;
GO

