-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE PROCEDURE CHECK_AGE
    @BIRTHDAY DATETIME
AS

DECLARE @NOW DATETIME

SELECT @NOW = GETDATE()

IF YEAR(@NOW) - YEAR(@BIRTHDAY) > 18
  PRINT 'above 18'
ELSE IF YEAR(@NOW) - YEAR(@BIRTHDAY) < 18
  PRINT 'below 18'
ELSE
  IF MONTH(@NOW) > MONTH(@BIRTHDAY)
    PRINT 'above 18'
  ELSE IF MONTH(@NOW) < MONTH(@BIRTHDAY)
    PRINT 'below 18'
  ELSE
    IF DAY(@NOW) >= DAY(@BIRTHDAY)
      PRINT 'above 18'
    ELSE
      PRINT 'below 18'

GO
