SQL 联合 select 从结果中获取最大长度

SQL Union select get max length from result

我要查询 SQL 服务器数据库:

Select [Surname] 
from [dbo].[customer] 

union 

Select 'Surname';

结果我有:

我想从结果 max(len( {result} )); 中获取。如果我使用:

Select max(len([Surname])) 
from [dbo].[customer];

这工作正常(结果我有 11),但我需要添加以比较列名。

查询:

Select max(len(Select [Surname] 
               from [dbo].[customer] 
               union 
               Select 'Surname'))

Return 错误:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'select'.

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ')'.

尝试将其更改为

Select max(len([Nazwisko]))
FROM (Select [Nazwisko] from [dbo].[wlasciciel] union Select 'Surname') t