如何获取文档类型,例如:地址或税收规则
How to fetch doctype eg: address or tax rule
我想获取文档类型。我该怎么做呢?我想添加一个单独的列,它将提供销售订单、采购订单等文档类型。第一行给我错误应该触发什么查询。请帮助我是 ERP Next 的新手。
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
要获取文档类型名称,您必须提供链接的文档类型名称,例如,
select
IT.name 作为 "IT No:Link/IT:120"
我不太清楚你所说的 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|
这是 select :
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 不允许直接将变量用作 table 名称,但您可以使用准备好的语句来实现,如下所示:
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;
table 名称现在也由一个变量指定,该变量由 'tab' 与之前声明的 docType
串联而成。
您会得到与上述相同的结果,但是 - 您可以避免在以后编辑时不小心在一个地方更改 table 名称而在另一个地方不更改。
我想获取文档类型。我该怎么做呢?我想添加一个单独的列,它将提供销售订单、采购订单等文档类型。第一行给我错误应该触发什么查询。请帮助我是 ERP Next 的新手。
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
要获取文档类型名称,您必须提供链接的文档类型名称,例如, select IT.name 作为 "IT No:Link/IT:120"
我不太清楚你所说的 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|
这是 select :
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 不允许直接将变量用作 table 名称,但您可以使用准备好的语句来实现,如下所示:
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;
table 名称现在也由一个变量指定,该变量由 'tab' 与之前声明的 docType
串联而成。
您会得到与上述相同的结果,但是 - 您可以避免在以后编辑时不小心在一个地方更改 table 名称而在另一个地方不更改。