【问题标题】:Issue with coalesce in T-SQLT-SQL 中的合并问题
【发布时间】:2024-04-27 23:00:02
【问题描述】:
Declare @Query Var-char(100)

select @Query= 'select coalesce(NULL,"test") as testing' 

Exec @Query

错误是

The name 'select coalesce(NULL,"test") as testing' is not valid identifier.

如何解决这个问题?

【问题讨论】:

    标签: sql-server tsql coalesce


    【解决方案1】:

    1) 通过键入两次来转义查询字符串中的 ' (不要像示例中那样使用双引号) 2) 将 () 放在 exec 命令之后

    Declare @Query Varchar(100)
    select @Query='select coalesce(NULL,''test'') as testing'
    Exec (@Query)
    

    【讨论】: