Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 多参数值_Sql_Eclipse_Birt - Fatal编程技术网

Sql 多参数值

Sql 多参数值,sql,eclipse,birt,Sql,Eclipse,Birt,当我试图从报告参数传递多个值时,BIRT有问题 我正在使用BIRT2.6.2和eclipse 我试图从级联参数组最后一个参数“JDSuser”中输入多个值。该参数允许有多个值,我使用的是列表框 为了能够做到这一点,我正在用where In语句编写sql查询,在语句中我用javascript替换文本。否则BIRT sql无法从报表参数中获取多个值 我的sql查询是 select jamacomment.createdDate, jamacomment.scopeId, jamacomment.co

当我试图从报告参数传递多个值时,BIRT有问题

我正在使用BIRT2.6.2和eclipse

我试图从级联参数组最后一个参数“JDSuser”中输入多个值。该参数允许有多个值,我使用的是列表框

为了能够做到这一点,我正在用where In语句编写sql查询,在语句中我用javascript替换文本。否则BIRT sql无法从报表参数中获取多个值

我的sql查询是

select jamacomment.createdDate, jamacomment.scopeId,
jamacomment.commentText, jamacomment.documentId,
jamacomment.highlightQuote, jamacomment.organizationId,
jamacomment.userId, 
organization.id, organization.name,
userbase.id, userbase.firstName, userbase.lastName,
userbase.organization, userbase.userName,
document.id, document.name, document.description,
user_role.userId, user_role.roleId,
role.id, role.name

from jamacomment jamacomment left join
userbase on userbase.id=jamacomment.userId
left join organization on
organization.id=jamacomment.organizationId
left join document on
document.id=jamacomment.documentId
left join user_role on
user_role.userId=userbase.id
right join role on
role.id=user_role.roleId

where jamacomment.scopeId=11
and role.name in ( 'sample grupa' )
and userbase.userName in ( 'sample' )
在beforeOpen状态下,该数据集的javascript代码为:

if( params["JDSuser"].value[0] != "(All Users)" ){
this.queryText=this.queryText.replaceAll('sample grupa', params["JDSgroup"]);
var users = params["JDSuser"];
//var userquery = "'";
var userquery = userquery + users.join("', '");
//userquery = userquery + "'";
this.queryText=this.queryText.replaceAll('sample', userquery);
}
我尝试了许多不同的报价变体,使用这一个,我没有收到错误消息,但如果我选择1个值,我从数据库中不会得到任何数据,但如果我选择至少2个值,我会得到最后选择的值数据

如果我取消注释其中一个附加引号脚本行,则会出现如下语法错误:

以下项目有错误: 表(id=597): +处理过程中发生异常。有关详细信息,请参阅以下消息:无法准备执行的查询 数据集:组织无法获取结果集元数据。 org.eclipse.birt.report.data.oda.jdbc.jdbception:SQL语句不返回ResultSet对象。SQL错误#1:您在 您的SQL语法;检查与您的MySQL对应的手册 在“rudolfs.sviklis”附近使用正确语法的服务器版本, 第25行的“样本”); com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;检查相应的手册 您的MySQL服务器版本需要使用正确的语法 第25行的“rudolfs.sviklis”、“sample”) 另外,我应该告诉你们,我是通过查看工作示例来实现这一点的。一切都是一样的,前面的代码导致了相同的语法错误,我把它改成了这个脚本,它也做了同样的事情。 示例如下所示:


如果有人能至少给我一个我应该做什么的线索,那就太好了。

您应该始终使用参数的value属性,即:

var users = params["JDSuser"].value;
没有必要用引号括住“userquery”,因为这些引号已经放在“sample”周围的SQL查询中。此外,还有一个错误,因为第行尚未定义userquery:

var userquery = userquery + users.join("', '");
这可能会在查询中引入诸如“null”之类的字符串。因此,删除对userquery变量的所有引用,只需在末尾使用以下表达式:

this.queryText=this.queryText.replaceAll('sample', users.join("','"));
< >我删除了联接表达式中的空白。最后,一旦工作正常,您可能需要通过测试该值是否为空来提高报表输入的健壮性:

if( params["JDSuser"].value!=null && params["JDSuser"].value[0] != "(All Users)" ){
  //Do stuff...

}

谢谢你的回复,虽然这对我没有帮助。我没有得到任何数据,我选择1个值或2个值。我想你节省了我几行代码和非空值也很好。还有其他想法吗?嗯,不过应该行得通。我建议将最终“this.queryText”的内容保存在全局变量中,并在报表的动态文本中临时显示该变量。因此,您将看到生成的查询,这可能会使查找错误变得容易。感谢Dominique,您对全局变量的建议帮助了我,我发现,我为组参数保留了不同的名称,因此它没有更改。这很有效。现在我必须想办法解决这个问题,向所有用户展示,因为它不起作用。我很高兴它有帮助。处理“All values”的一种简单方法是添加一个“OR”子句,检查dataset参数的值是否等于特定的常量值。否则,您的脚本应该修改为包含查询的最后一个“AND”子句,当且仅当参数值不是“All values”时。不幸的是,我无法使“All values”起作用,它只将其作为简单的All Users文本来获取,尽管我已经计算了一列,该列应该为所有用户选项创建条目。我假设它不会以某种方式将这些值提供给所有用户?你知道吗?