select 

	concat('UPDATE TBNFS SET CHAVE_ACESSO = ''',V.ChavedeAcesso,''' WHERE COMANDA = fn_lpad(''',A.Loja,''',3,''0'')||fn_lpad(''',A.Comanda,''',8,''0'');') AS sql

FROM [AlphaInd 5].[dbo].[Comandas] A, [AlphaInd 5].[dbo].[NFSaida] v
WHERE a.data >= cast('2022-08-01' as date) 
and v.Numero = a.NotaFiscal
and v.Loja = a.NotaFiscal_Loja
and v.Serie = v.Serie
