sql - MS Access 查询中的语法错误?

标签 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 中预览数据 TableView 时,它要求提供 Customer.LocationCustomer.CityCustomer.StateCustomer .Country 然后显示 CustomerId=11 的结果

enter image description here

当我单击“数据 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/

相关文章:

.net - Windows 窗体 : Why does output to textbox of long running algorithm stop after a while?

vba - 使用 VBA Access 发送电子邮件时如何插入换行符

sql - 有人可以解释为什么以下查询的功能不同吗?从字面上看,两者之间的唯一区别是

mysql - 这是什么样的主键?

java - 在 App Engine 上部署应用程序后出现时间戳问题

c# - 如何在 Windows 应用程序中处理 Ctrl + Break 或 Ctrl + Pause

c# - 将字节数组转换为 int32

ms-access - "invalid use of null"用于返回变体的 vba 函数

c# - 将 csv 中的长数字导入到 access 中

sql - 查询得到每一项的最高排名