我将 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 中预览数据 TableView 时,它要求提供 Customer.Location、Customer.City、Customer.State 和 Customer .Country 然后显示 CustomerId=11 的结果
当我单击“数据 TableView ”时,我需要显示客户详细信息。
实际上,在客户表位置中,其字段名称是 BLocation,城市是 BCity,州是 BState,国家是 BCountry,但如果我给出 Select LocationName from Location where LocationId=Customer.BLocation
它显示语法错误。
帮我解决这个问题?
最佳答案
谢谢你们,这段代码运行良好
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;
关于sql - MS Access 查询中的语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21494681/