Das Alter einer Person

DECLARE @d DATETIME
SET @d = '23.07.1968'
SELECT
     DATEDIFF(yyyy,CAST(@d AS DATETIME),GETDATE()) 
     - 
     (CASE WHEN DATEADD(yyyy,DATEDIFF(yyyy,CAST(@d AS DATETIME),GETDATE()),CAST(@d AS DATETIME)) > 
     GETDATE() THEN 1 ELSE 0 END)

            
----------- 
35

(1 row(s) affected)

Noch kein Feedback
Einen Kommentar hinterlassen

Ihre E-Mail-Adresse wird nicht auf dieser Seite angezeigt.
SchlechtExzellent
(Zeilenumbrüche werden zu <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)
Trackback-Adresse für diesen Eintrag

http://www.insidesql.org/blogs/htsrv/trackback.php?tb_id=1096