Sql Alation查询表单-参数不使用;在;操作人员

Sql Alation查询表单-参数不使用;在;操作人员,sql,db2,alation,Sql,Db2,Alation,我需要创建一个带有输入参数的查询表单,该参数接受多个字符串输入 根据Alation的文件,代码很简单: 对于传递多个值: select * from order_history where customer_id in (${customer_id | type : raw}); select * from order_history where customer in ${customer | type : raw}; 对于字符串多个值: select * from order_his

我需要创建一个带有输入参数的查询表单,该参数接受多个字符串输入

根据Alation的文件,代码很简单:

对于传递多个值:

select * from order_history 
where customer_id in (${customer_id | type : raw});
select * from order_history 
where customer in ${customer | type : raw};
对于字符串多个值:

select * from order_history 
where customer_id in (${customer_id | type : raw});
select * from order_history 
where customer in ${customer | type : raw};
(我不知道传递多个值和字符串多个值之间有什么区别,所以如果有人能分享我的见解,我将不胜感激)

我的代码:

SELECT * FROM WTY_DM.PRODUCT
WHERE VIN IN ${VIN | type : raw};
结果: 它按预期生成参数选项:

但是,无论我使用的是“传递多个值”版本还是“字符串多个值”版本,框中所示的逗号分隔列表都会引发相同的错误:

预期结果:
VIN与参数字段中的任一项匹配的表中的所有内容。

我们不确定您的声明,尤其是${customer\u id | type:raw}部分。为了更好地理解您的问题,我们可能需要有关客户id、类型和原始数据的更多详细信息

但一般来说,这部分应该像一个单词,比如1、'a'或'BBB'。或2个或更多带括号的单词,如(1,2),('A','B')或('AAA','BBB')

下面是IN和result的示例使用脚本,供您在AIX Db2 V11.5上参考

#!/bin/sh

db2 -v "drop db db1"
db2 -v "create db db1"
db2 -v "connect to db1"
db2 -v "create table t1 (c1 int, c2 char(10), c3 int)"
db2 -v "insert into t1 values (1,'AA',1)"
db2 -v "insert into t1 values (1,'AB',2)"
db2 -v "insert into t1 values (2,'BB',3)"
db2 -v "insert into t1 values (2,'AB',4)"

VAR1='A'
VAR2='B'

db2 -v "select * from t1 where c1 in ( 1 , 2 )"
db2 -v "select * from t1 where c1 in 2"
db2 -v "select * from t1 where c2 in '${VAR1}${VAR2}'"
db2 terminate
以下是三个select语句的结果:

C1          C2         C3
----------- ---------- -----------
          1 AA                   1
          1 AB                   2
          2 BB                   3
          2 AB                   4

希望这有助于您的理解。

Alation移动了他们的文档和帮助中心,因此您的链接似乎不再有效。我找到了新的一个,格式化了它,并在下面分享给未来寻找它的人

为了解决您的具体问题,我认为您可以通过在其周围添加括号来解决问题,请尝试以下方法: 从WTY_DM.PRODUCT中选择* 其中VIN为(${VIN类型:raw})

然后您必须发布查询并单击“共享为表单”

这里的文档

查询表单和参数

select * from order_history
where customer_id in (${customer_id  type : raw});
select top 10 * from order_history
where my_date = ${my_date  type : date};
select top 10 * from order_history
where my_date between (${start_date  type : date}) and (${end_date  type : date});
select * from order_history
where customer = ${customer};
select * from order_history
where customer in ${customer  type : raw};
如果需要使用不同的列值多次重新运行查询,则每次运行时手动编辑脚本可能会变得单调乏味。例如,使用不同的状态或日期运行相同的查询

为了简化该过程,您可以通过使用以下表达式替换所需常量来创建查询表单(也称为查询参数):

${variable_name | eg:example value | default:default_value | help:help text | type:type}
当变量_name成为表单字段的名称时,示例值在表单字段为空时显示在表单字段中,帮助文本显示在表单字段的左侧

该类型可以采用以下值:

整数

日期

生的

使用type指定用于改进解析的变量的类型,尽管可以省略它。type:raw告诉Alation按原样接受变量输入

单个值

select * from order_history
where customer_id = ${customer_id};
select * from order_history
where col LIKE '${string}';
带有like的单个值

select * from order_history
where customer_id = ${customer_id};
select * from order_history
where col LIKE '${string}';
传递多个值

select * from order_history
where customer_id in (${customer_id  type : raw});
select top 10 * from order_history
where my_date = ${my_date  type : date};
select top 10 * from order_history
where my_date between (${start_date  type : date}) and (${end_date  type : date});
select * from order_history
where customer = ${customer};
select * from order_history
where customer in ${customer  type : raw};
日期

select * from order_history
where customer_id in (${customer_id  type : raw});
select top 10 * from order_history
where my_date = ${my_date  type : date};
select top 10 * from order_history
where my_date between (${start_date  type : date}) and (${end_date  type : date});
select * from order_history
where customer = ${customer};
select * from order_history
where customer in ${customer  type : raw};
日期多个值

select * from order_history
where customer_id in (${customer_id  type : raw});
select top 10 * from order_history
where my_date = ${my_date  type : date};
select top 10 * from order_history
where my_date between (${start_date  type : date}) and (${end_date  type : date});
select * from order_history
where customer = ${customer};
select * from order_history
where customer in ${customer  type : raw};
字符串值

select * from order_history
where customer_id in (${customer_id  type : raw});
select top 10 * from order_history
where my_date = ${my_date  type : date};
select top 10 * from order_history
where my_date between (${start_date  type : date}) and (${end_date  type : date});
select * from order_history
where customer = ${customer};
select * from order_history
where customer in ${customer  type : raw};
字符串多个值

select * from order_history
where customer_id in (${customer_id  type : raw});
select top 10 * from order_history
where my_date = ${my_date  type : date};
select top 10 * from order_history
where my_date between (${start_date  type : date}) and (${end_date  type : date});
select * from order_history
where customer = ${customer};
select * from order_history
where customer in ${customer  type : raw};
例如,如果原始查询为:

SELECT * from order_history where order_date = '2016-01-01';
您的查询表单可能如下所示:

SELECT * from order_history where order_date = ${my_date | eg:2016-01-01 | type:date | default:2016-02-14 | help:enter order date in YYYY-MM-DD format};

若要访问模板化查询的SQL自由表单视图,请选择“共享查询为表单”选项。

如果
谓词中的
包含多个表达式,则需要使用括号。@mustaccio,如
中的where customer\u id IN(${customer\u id | type:raw})
示例?我试过了。同样的错误。看起来你的软件(或者你——不知道是哪一个)提供了不带引号的假定字符文本,所以它们被视为标识符。我不认为你理解这个问题,它是一个名为Alation的工具特有的,它是如何将具有特定变量语法的SQL解释为非SQL用户的简单UI的。