SQL: 嵌套合并和转换

SQL: Nesting coalesce and convert

版本是 SQL Server 2012 with SQL Server Management Studio

我的作业要求我创建一个包含 PeopleIDHireDateTermDate 列的 table。 TermDate 将重命名为 Current 并将 Null 值合并为 'Current Employee'。这里的问题是 TermDate 是一个 Null 列,需要转换为文本列才能合并...

我试过很多调整,但我似乎无法弄清楚。这是我当前的迭代。现在我收到错误

Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'TermDate'.

代码:

select 
   PeopleID
   ,HireDate
   ,coalesce(convert(varchar(10), TermDate, 1) TermDate, 'Current Employee') as [Current]
from 
   WORKERS

感谢帮助

为什么表达式中有两次 TermDate?你只需要它一次作为 convert():

的参数
select PeopleID, HireDate,
       coalesce(convert(varchar(10),TermDate, 1), 'Current Employee') as [Current]
from WORKERS;
select  PeopleID
        ,HireDate
        ,case 
            when TermDate is NULL then 'Current Employee')
            else convert(varchar(10), TermDate, 1)
         end as [Current]
    from WORKERS