DECLARE @replanValueQuery varchar(255);
SET @replanValueQuery = 'SELECT ' + QUOTENAME(@replanFieldName) + ' FROM [CustomFieldValue] WHERE [ObjectId]=' + CAST(@objectId as varchar(36));
DECLARE @replanValue varchar(5);
EXECUTE @replanValue = @replanValueQuery;
ejecute tu query y me arrojaba errores de declaracion, declare ambas var q estan dentro de la query..algo asi quedo :
DECLARE @replanValueQuery varchar(255)
declare @replanFieldName varchar(255)
declare @objectId varchar(255)
SET @replanValueQuery = 'SELECT ' + QUOTENAME(@replanFieldName) + ' FROM [CustomFieldValue] WHERE [ObjectId]=' + CAST(@objectId as varchar(36));
select @replanValueQuery
espero sirva...