سؤال

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