MS Access Query中的语法错误?

时间:2014-02-01 05:54:13

标签: sql winforms ms-access

我将7列合并为单列,这些列都是单列的地址。最初的位置,城市,州和国家/地区存储代码其显示值在相应的表中。所以我在下面的查询中加入了所有内容。

SELECT CustomerName, CustomerId, ContactPerson, 

((BFlatNo +','+ BPremises +','+ BStreet +','+ BArea) + ',' +
(select LocationName from Location where LocationId = Customer.Location) + ',' +
(select CityName from City where CityId = Customer.City) + ',' +
(select StateName from State where StateId = Customer.State) + ',' +
(select CountryName from Country where CountryId = Customer.Country) + ',' + 
(BMobileNumber) ) AS BillingAddress, 

((DFlatNo +','+ DPremises +','+ DStreet +','+ DArea) + ',' +
 (select LocationName from Location where LocationId = Customer.Location) + ',' +
 (select CityName from City where CityId = Customer.City) + ',' +
 (select StateName from State where StateId = Customer.State) + ',' +
 (select CountryName from Country where CountryId = Customer.Country) + ',' + 
(DPhone) ) AS DeliveryAddress

FROM Customer
WHERE Customer.CustomerId = 11;

在MS Access中预览数据表视图时,它要求 Customer.Location Customer.City Customer.State & Customer.Country 然后显示CustomerId = 11的结果

enter image description here

单击数据表视图时,我需要显示客户详细信息。 实际上在Customer表的位置,它的fieldname是BLocation,City是BCity,State是BState&国家是BCountry但是如果我给Select LocationName from Location where LocationId=Customer.BLocation它显示语法错误。

帮我解决这个问题?

1 个答案:

答案 0 :(得分:2)

谢谢你们这个代码工作正常

SELECT CustomerName, CustomerId, ContactPerson,

((BFlatNo +','+ BPremises +','+ BStreet +','+ BArea)+','+
(select LocationName from Location where LocationId=Customer.BLocation)+','+
(select CityName from City where CityId=Customer.BCity)+','+
(select StateName from State where StateId=Customer.BState)+','+
(select CountryName from Country where CountryId=Customer.BCountry)+','+ (BMobileNumber)) AS BillingAddress,

((DFlatNo +','+ DPremises +','+ DStreet +','+ DArea)+','+
(select LocationName from Location where LocationId=Customer.DLocateion)+','+
(select CityName from City where CityId=Customer.DCity)+','+
(select StateName from State where StateId=Customer.DState)+','+
(select CountryName from Country where CountryId=Customer.DCountry)+','+ (DPhone)) AS DeliveryAddress

FROM Customer;
相关问题