【问题标题】:Trying to join a directory name in an Excel file to a value In another column with different lengths尝试将 Excel 文件中的目录名称连接到另一个长度不同的列中的值
【发布时间】:2017-07-30 22:20:06
【问题描述】:

我已在 Excel 文件中打印出文件和文件夹的目录。目录末尾的文件夹名称与 Excel 文件中另一列中的别名匹配。

我正在尝试使用右连接将它们连接在一起。这是使用 Excel 文件作为链接表的 Access,我正在尝试根据它们在一个文件中的别名列出目录。

当我尝试获取一列中的值的 Len 并将其放入查询中时,我收到语法错误连接错误。

这里是查询。不知道是否需要使用子串?

SELECT [General Acccounts].[Account #], [General Acccounts].[Account Name], 
[General Acccounts].[Customer Alias], [General Acccounts].[Start Date]
FROM EOM_On_Hand_Counter LEFT JOIN [General Acccounts] ON 
Right(EOM_On_Hand_Counter.DirectoryName,)(len([General Accounts].[Customer 
Alias])) = [General Acccounts].[Customer Alias]
GROUP BY [General Acccounts].[Account #], [General Acccounts].[Account Name], [General Acccounts].[Customer Alias], [General Acccounts].[Start Date];

您可以看到我想将目录名称的右侧连接到一般帐户表中的客户别名值,因为它们匹配。当我在 Access 中使用 Len 函数时,它在 SQL 查询中不起作用。有人有什么建议吗?

【问题讨论】:

  • 删除Right()函数中逗号后的右括号和左括号。
  • @Parfait 试过这个,它说 Syntax Error In Join Operation 。我在逗号之后删除了 ( 并做了 len 运算符。SELECT [General Acccounts].[Account #], [General Acccounts].[Account Name], [General Acccounts].[Customer Alias] FROM [General Acccounts] INNER JOIN EOM_On_Hand_Counter ON [General Acccounts].[Customer Alias] = right(EOM_On_Hand_Counter.DirectoryName,Len([General Accounts].[Account Name])) GROUP BY [General Acccounts].[Account #], [General Acccounts].[Account Name], [General Acccounts].[Customer Alias]
  • 请提供两个表的示例数据,以便我们重现。
  • @Parfait EOM_On_Hand_Counter.DiretoryName = S:\admins\EOM\Tyco / [General Accounts].[Customer Alias] = Tyco 我正在尝试将客户别名的长度与目录名称右侧相匹配。由于它们都是 4 我需要客户别名的长度。 EOM_On_Hand_Counter.DirectoryName = S:\admins\EOM\Sprint / [General Accounts].[Customer Alias] = Sprint 所以你可以看到我想匹配那个正确的六个字符。基本上客户别名是与结束目录名称相同的正确字符。
  • 请用数据编辑帖子。在 cmets 中很难阅读。

标签: sql ms-access join


【解决方案1】:

由于目录名称是固定长度的 s:\admins\EOM\ 我可以执行以下操作:

SELECT [General Acccounts].[Customer Alias], 
EOM_On_Hand_Counter.DirectoryName, EOM_On_Hand_Counter.FileName, 
EOM_On_Hand_Counter.DateCreated
FROM [General Acccounts] INNER JOIN EOM_On_Hand_Counter ON [General 
Acccounts].[Customer Alias]  = mid(EOM_On_Hand_Counter.DirectoryName,15,20)
GROUP BY [General Acccounts].[Customer Alias], 
EOM_On_Hand_Counter.DirectoryName, EOM_On_Hand_Counter.FileName, 
EOM_On_Hand_Counter.DateCreated;

将长度保留在末尾 20 以补偿最长的客户别名,并且查询返回我需要的内容。

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 2011-10-09
    • 1970-01-01
    相关资源
    最近更新 更多