我正在尝试将MS Access查询转换为SQL Server,但我无法找出以下代码的SQL Server等效项:
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,
这是我未完成的尝试:
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,
答案 0 :(得分:0)
我希望下面的查询会给你所需的输出
select top 1 (select case When DATEDIFF(year, DateOfBirth, '31-Aug-2012') < 18 Then 'Parent/Guardian of:' else Null End ) from table_name