根据字符串值过滤列时,T-SQL数据透视格式化意外标识符

时间:2021-02-11 22:21:17

Can someone explain what is wrong with this syntax for creating a pivot in SQL Server Management Studio? I tried adding the identifier ([Name].'email') with no success. 根据字符串值过滤列时,T-SQL数据透视格式化意外标识符

有人可以解释在SQL Server Management Studio中创建数据透视表的这种语法有什么问题吗?我尝试添加标识符([Name]。'email')但没有成功。

Error message when executed:

执行时出现错误信息:

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'email'.

消息102,级别15,状态1,行6'电子邮件'附近的语法不正确。

1 个解决方案

#1


3  

Select ID
      ,email as EMail
      ,phone as Phone
From (
....
) aaa
pivot (max([Data]) for [Name] in ([email],[phone]) ) pvt

If your system is not case sensitive, you can get away with

如果您的系统不区分大小写,则可以逃脱

Select *
From (
....
) aaa
pivot (max([Data]) for [Name] in ([Email],[Phone]) ) pvt

#1


3  

Select ID
      ,email as EMail
      ,phone as Phone
From (
....
) aaa
pivot (max([Data]) for [Name] in ([email],[phone]) ) pvt

If your system is not case sensitive, you can get away with

如果您的系统不区分大小写,则可以逃脱

Select *
From (
....
) aaa
pivot (max([Data]) for [Name] in ([Email],[Phone]) ) pvt