C# Crystal Reports记录选择公式中的SQL Convert(varchar,)等效项

C# Crystal Reports记录选择公式中的SQL Convert(varchar,)等效项,c#,mysql,sql-server,crystal-reports,crystal-reports-2010,C#,Mysql,Sql Server,Crystal Reports,Crystal Reports 2010,我有一个sql查询where子句,如下所示: WHERE ("Table1"."count"<>"Table1"."onhand" OR "Table2"."batch_code" IS NOT NULL OR ("Table1"."BatchMinVariance"<>0 OR "Table1"."BatchMaxVariance"<>0) ) 注:条件4是新的条件,我使用了sql转换函数,因为这些

我有一个sql查询where子句,如下所示:

WHERE ("Table1"."count"<>"Table1"."onhand"
       OR "Table2"."batch_code" IS NOT NULL        
       OR ("Table1"."BatchMinVariance"<>0 OR "Table1"."BatchMaxVariance"<>0)
       )
注:条件4是新的条件,我使用了sql转换函数,因为这些是布尔字段,所以只显示值为01或10的行。sql查询为我提供了预期的结果,但我无法找到与此条件对应的Crystal。 对于条件4,我尝试:

OR (TOTEXT(TONumber({Table3.in_snapshot_yn}), 0)&""&TOTEXT(TONumber({STAKE_SERIALNO.counted_yn}), 0) IN ("01, 11") <> true) 
我在报告中对此进行了测试,以了解crystal是否喜欢,crystal是否会抱怨。但是当我把它作为条件4放在代码中时,我不喜欢它。给出缺少括号的lame错误。我知道这不是一个括号的问题,肯定与条件有关

    WHERE 
    ("Table1"."count"<>"Table1"."onhand"
           OR "Table2"."batch_code" IS NOT NULL            
           OR ("Table1"."BatchMinVariance"<>0 OR "Table1"."BatchMaxVariance"<>0)
           OR (CONVERT(varchar, "Table3".in_snapshot_yn) + CONVERT(varchar, "Table3".counted_yn) IN ('01', '10'))
   )
完全CR等效条件如下所示:

    ({TABLE1.count} <> {TABLE1.onhand} 
OR (not isnull({Table2.batch_code}) 
OR ({TABLE1.BatchMinVariance} <> 0 OR {TABLE1.BatchMaxVariance} <> 0) )
OR NOT (TOTEXT(TONumber({Table3.in_snapshot_yn}), 0)&""&TOTEXT(TONumber({Table3.counted_yn}), 0) IN ("01, 11")) )

如有任何提示,将不胜感激。我正在使用SQL Server 2014和CR 13。

您应该创建一个SQLExpression。SQLExpression将具有与数据库语法相同的语法,主要优点是它将在服务器上执行。您可以将其添加到记录选择公式中。如果您使用Crystal功能,所有记录都将在本地下载和过滤。如果使用SQL表达式,Crystal将能够生成WHERE子句并将其发送到服务器,因此下载到计算机上的记录数量将大大减少

我找到了。在我的新条件下,双引号有问题

TOTEXT(TONumber({Table3.in_snapshot_yn}), 0)&""&TOTEXT(TONumber({Table3.counted_yn}), 0) IN ("01, 11")
只要我把它们改成单引号,它就工作得很好。我不知道它为什么会这样做。正如我所说的,记录选择在报告中做得很好,所以我在Crystal中没有庞大的数据集

请参阅下面完整的晶体等效记录选择

({TABLE1.count} <> {TABLE1.onhand} 
OR (not isnull({Table2.batch_code}) 
OR ({TABLE1.BatchMinVariance} <> 0 OR {TABLE1.BatchMaxVariance} <> 0) )
OR NOT (TOTEXT(TONumber({Table3.in_snapshot_yn}), 0)&''&TOTEXT(TONumber({Table3.counted_yn}), 0) IN ('01, 11')) )
答案到此为止

对于用户@Lan。。为了防止您需要知道我是如何在c中完成这项工作的,我已将代码粘贴到下面

var recordSelection = new List<string>();
recordSelection.Add(<crystal equivalent where clause as above>);
reportDocument.RecordSelectionFormula(recordSelection);
// FYI reportDocument is initialised like this ReportDocument reportDocument;

谢谢我的做法与此类似,因为在动态执行查询时,数据会在到达报表之前进行过滤。否,Crystal无法将ToText和ToNumber转换为SQL语法。因此,将下载所有记录,然后Crystal将在本地应用过滤器。假设您有一个包含100k条记录的表,并且希望获取ID为'ABC'的客户的记录。如果使用SQL表达式,Crystal将向数据库发送如下SQL:SELECT。。。从ID='ABC'的表中。如果您使用ToText函数或任何其他Crystal函数,SQL将被选中。。。从桌子上。Where条款将不准备。所有100k记录都将在本地下载和筛选。请查看我的答案。有一个评论给你。
var recordSelection = new List<string>();
recordSelection.Add(<crystal equivalent where clause as above>);
reportDocument.RecordSelectionFormula(recordSelection);
// FYI reportDocument is initialised like this ReportDocument reportDocument;