0

我正在尝试将 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, 
4

1 回答 1

0

我希望下面的查询会给你所需的输出

 select top 1 (select case When  DATEDIFF(year, DateOfBirth, '31-Aug-2012') < 18 Then 'Parent/Guardian of:' else Null  End  ) from table_name
于 2013-02-12T16:27:49.073 回答