如何获取文档类型,例如:地址或税收规则

时间:2019-12-09 05:57:05

标签: erpnext frappe

我想获取文档类型。我该怎么做呢?我想添加一个单独的列,该列将提供诸如销售订单,采购订单等文档类型。第一行给我错误,应该触发什么查询。请帮助我是ERP的下一个新手。

SELECT
    AD.ref_doctype AS “Doctype:Link/User:120”,
    AD.name AS “Doc#:Link/Doctype:120”,
    AD.owner AS “Created By:Link/User:120”,
    AD.modified AS “Modified On:Date:120”
FROM tabAddress AS AD

WHERE
    DATEDIFF(now(),AD.modified) BETWEEN 1 AND 30

UNION ALL

SELECT
    TR.name AS “Doc#:Link/Doctype:120”,
    TR.owner AS “Created By:Link/User:120”,
    TR.modified AS “Modified On:Date:120”
FROM tabTax Rule AS TR
WHERE
    DATEDIFF(now(),TR.modified) BETWEEN 1 AND 30

UNION ALL

SELECT
    IT.name AS “Doc#:Link/Doctype:120”,
    IT.owner AS “Created By:Link/User:120”,
    IT.modified AS “Modified On:Date:120”
FROM tabItem AS IT
WHERE
    DATEDIFF(now(),IT.modified) BETWEEN 1 AND 30

2 个答案:

答案 0 :(得分:0)

要获取文档类型名称,您必须提供链接的文档类型名称,例如, 选择   IT.name为“ IT No:Link / IT:120”

答案 1 :(得分:0)

我还不太清楚您对docType字段的含义。

您想要这样的结果吗?

Doctype:Link/User:120|Doc#:Link/Doctype:120|Created By:Link/User:120|Modified On:Date:120|
---------------------|---------------------|------------------------|--------------------|
Email Account        |Jobs                 |Administrator           | 2019-12-04 06:07:55|
Email Account        |Notifications        |Administrator           | 2019-12-01 05:25:53|
Email Account        |Replies              |Administrator           | 2019-12-01 05:25:53|
Email Account        |Sales                |Administrator           | 2019-12-04 06:07:55|
Email Account        |Support              |Administrator           | 2019-12-04 06:07:55|

这是精选内容:

set @docType = "Email Account";
SELECT
    @tabDocType  AS `Doctype:Link/User:120`,
    AD.name AS `Doc#:Link/Doctype:120`,
    AD.owner AS `Created By:Link/User:120`,
    AD.modified AS `Modified On:Date:120`
FROM `tabEmail Account` AS AD

请注意字段别名上的反引号!所有这些在SQL中都有不同的含义:

"
'
`

最后一个反引号用于引用数据库实体。您试图将“Doctype:Link/User:120”与双引号一起使用,以声明纯文本。使用反引号会将别名转换为可以从其他位置引用的数据库实体。

MariaDb不允许直接将变量用作表名,但是您可以使用准备好的语句来做到这一点,例如:

set @docType = "Email Account";
set @tabDocType = CONCAT('tab', @docType);
SET @sql_text = concat('

SELECT 
    "', @docType, '"  AS `Doctype:Link/User:120`
  , AD.name AS `Doc#:Link/Doctype:120`
  , AD.owner AS `Created By:Link/User:120`
  , AD.modified AS `Modified On:Date:120`
FROM `', @tabDocType, '` as AD;

');


PREPARE stmt FROM @sql_text;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

表名现在也由一个变量指定,该变量由'tab'与之前声明的docType的串联创建。<​​/ p>

获得与上述相同的结果,但是-避免在以后进行编辑时在一个地方而不是另一个地方意外更改表名。