I’m trying to convert an MS Access query to SQL server, but I can’t figure out the SQL server equivalent for the following code:
First(IIf(DateDiff("yyyy",[DateOfBirth],"31-Aug-2012")+Int(Format("31-Aug-2012","mmdd")<Format([DateOfBirth],"mmdd"))<18,'Parent/Guardian of:',Null)) AS PG,
First(IIf(DateDiff("yyyy",[DateOfBirth],Now())+Int(Format(Now(),"mmdd")<Format([DateOfBirth],"mmdd"))<18,'Parent/Guardian of:',Null)) AS PG_old,
Here is my unfinished attempt:
First(CASE WHEN (DateDiff("yyyy",[DateOfBirth],"31-Aug-2012")+Int((DATEPART(mm,(CONVERT(DATE,"31-Aug-2012",103))) + (DATEPART(dd,(CONVERT(DATE,"31-Aug-2012",103)))))<Format([DateOfBirth],"mmdd")) < 18 THEN 'Parent/Guardian of:'
ELSE Null)END) AS PG,
i hope below query would give you required output