我使用SQL Server Management Studio版本11.0.3128.0与SQL Server 2012的左连接上的SQL Server Management Studio语法错误?
我有这个疑问,当我运行它,但SSMS口口声声说是我的SQL语法错误的作品,虽然它运行良好。该错误是
多部分标识符bsr.budgetId无法绑定
和第2行上
SELECT
bh.cpNo as CodigoDoPedido,
df.registerDate as DataFechamento,
meh.pedidoCliente as NumeroDePedidoDoCliente,
bh.deliveryDate as DataEntrega,
ch.clientText as NomeCliente,
ah.addressCep as CEPEnderecoCliente,
ah.addressDistrict as DistritoEnderecoCliente,
ah.addressInfo as InfoEnderecoCliente,
ah.addressInfo2 as Info2EnderecoCliente,
ah.addressInfo3 as Info3EnderecoCliente,
ah.addressText as TextEnderecoCliente,
cih.cityText as CidadeEnderecoCliente,
sh.stateText as EstadoEnderecoCliente,
coh.countryText as PaisEnderecoCliente,
comh.commInfo as TelefoneCliente,
buh.buildText as ProjetoOrcamento,
bh.valorCustoDocumentacao as CustoDocumentacaoOrcamento,
bh.valorTotalEstrangeiro as ValorTotalEstrangeiroOrcamento
from
_budget_hdr as bh
left join (
select
bsr2.budgetId,
min(bsr2.registerId) as registerId
from _budgetStatus_reg as bsr2
where bsr2.budgetStatusId = 4
group by bsr2.budgetId
) AS bsr on
bsr.budgetId = bh.budgetId
left join _budgetStatus_reg as df on
df.budgetId = bsr.budgetId AND
df.registerId = bsr.registerId
left join _minutaEletronica_hdr as meh on
meh.minutaId = bh.minutaId
left join _client_hdr as ch on
ch.clientId = bh.clientId
left join _clientAddress_rel as car on
car.clientId = ch.clientId and
car.addressTypeId = 0
left join _address_hdr as ah on
ah.addressId = car.addressId
left join city_hdr as cih on
cih.cityId = ah.cityId
left join state_hdr as sh on
sh.stateId = ah.stateId
left join country_hdr as coh on
coh.countryId = ah.countryId
left join _clientComm_rel as ccr on
ccr.clientId = ch.clientId
left join _comm_hdr as comh on
comh.commId = ccr.commId
left join build_hdr as buh on
buh.buildId = bh.buildId
where
bh.budgetId = 76089;
我一个
语法错误放弃,我真的不知道我的SQL有什么问题。
编辑
我改变了重复别名BSR2,它并没有解决问题
左连接上的子查询具有相同的别名'bsr'。删除里面的子查询中的别名,我认为这将解决它。 –
您正在使用bsr两次,也许使用其他名称 – Alam
更改了别名,相同问题 –