Declare @Query Var-char(100)

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

Exec @Query

error is

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

how to fix this?

有帮助吗?

解决方案

1) escape the ' within the query string by typing it twice (don't use the double quotes as in your example) 2) put () after the exec command

Declare @Query Varchar(100)
select @Query='select coalesce(NULL,''test'') as testing'
Exec (@Query)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top