DROP FUNCTION IF EXISTS  dbo.fnGetHetNapja
GO

CREATE FUNCTION dbo.fnGetHetNapja (
   @date datetime
  ,@hetNapjaTipusTypeId int = 40
)
  RETURNS int
BEGIN  
  DECLARE @value INT
  
  SELECT @value = MIN(ID) 
  FROM T_DICTIONARYITEMBASE d 
  WHERE d.C_DICTIONARYTYPEID = @hetNapjaTipusTypeId
    AND d.C_VALUE = DATEPART(dw, @date)
  
  RETURN @value  
END

GO
