Tenho o problem a seguir
Drop table #notaserr
Drop table #Bases
select distinct idpedidoprojeto, idnf, datahora, status, idprojeto into #NotasErr
from nf
where status in (62,65,66,70,85,86)
and datahora >= dateadd ( hh , -12, getdate() )
order by datahora desc
select idprojeto, Descricao,siglaProjeto,Base, '['+substring(StringConexao,8,25)+']' Conexao, row_Number() over(partition by null order by Base) id
into #Bases
from Projeto
where stringConexao is not null
and descricao not in ('Lilly PharmaSystem')
declare @teste nvarchar (max)
select @teste = 'select distinct nf.idnf, nf.pedido from '+Conexao+'.'+Base+' TBLNF NF (NOLOCK)' from #bases
exec (@teste)