SQL "WITH" 在 Spotfire 中不起作用

SQL "WITH" doesn't work in Spotfire

我尝试从 MS SQL 服务器 运行 在 Spotfire (7.8) 中查询。

一切都适用于简单的查询,但是我无法使通用 table 表达式正常工作。

这是一个非常简单的示例,运行 没有来自 MS SQL Server Management studio 的问题:

with test as ( select * from myTable)
select * from test 

在 Spotfire 中出现以下错误:

An error occurred when executing a query in the external data source.

External error:
Incorrect syntax near the keyword 'with'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Incorrect syntax near ')'.

我也尝试按照建议添加 ; here,但没有帮助:

An error occurred when executing a query in the external data source.

External error:
Incorrect syntax near ';'.
Incorrect syntax near ')'.

我尝试将 ;s 添加到不同的位置(在 select 语句结束后,右括号...),但无法正常工作。

我真正的查询很长,所以将所有内容放在一起并摆脱 CTE 并不是一个真正的选择。

澄清一下,我已经尝试了以下所有位置和组合,但均未成功:

;with test as ( select * from myTable)
select * from test 

with test as ( select * from myTable;)
select * from test 

with test as ( select * from myTable);
select * from test 

TL;DR 如果您拥有所有正确的权限,并且不止一次或两次使用 Spotfire,请制作一个存储过程(详见下文)。如果您还没有,抱歉,您将不得不将所有 CTE 放在一个非常长的查询中。


所以我发现 Spotfire 实际上只会在标准信息 Link 或直接连接中 运行 "one query"。

遗憾的是,这意味着它与临时表或 CTE 相处得不是很好。

如果将所有内容放在一起确实不是一种选择,您将不得不将其转换为存储过程,正如肖恩在评论中提到的那样。

唯一的缺点是它需要比许多 Spotfire 用户更多的访问权限。

首先,您需要在数据库中创建存储过程,或者联系可以为您创建存储过程的人员。

其次,您将需要使用信息设计器(这同样需要正确的权限)。如果您有访问权限,Information Designer 位于工具下。当你打开它时,你会在顶部看到 "Create Information Link",在它下面你会看到像 "Create Elements" 这样的东西,其中包括 "Procedure".

这是您 select 来自数据源的存储过程。

然后您需要制作一个信息 Link ("Create Information Link"),以及 select 您刚刚构建的程序,它现在位于 "Elements" 选项卡中。