简体   繁体   English

Crystal Report从“类似” SQL传递存储过程参数

[英]Crystal Report Passing Stored Procedure Parameter from “Like” Sql

I have problems in passing stored procedure parameter to crystal report. 将存储过程参数传递给Crystal报表时遇到问题。 I tried passing parameter but the result is not like i expected. 我尝试传递参数,但结果与我预期的不同。 the parameter can be passed, but the problem is the value of parameter must be exactly the value of parameter. 可以传递参数,但是问题是参数的值必须正好是参数的值。 and in my case, i'd like to make the report that can show the report with "like" query, so the parameter can be one, two, or other letter on the real value. 在我的情况下,我想制作一个可以通过“ like”查询显示报告的报告,因此该参数可以是真实值上的一个,两个或其他字母。

i've tried use the group and record in selection formula, but the result same, the parameter must exactly the value, and cannot just part of letter member of the value. 我试过使用组并记录在选择公式中,但结果相同,该参数必须正好是该值,并且不能只是该值的字母成员的一部分。

my table maybe bit like this : 我的桌子可能像这样:

employee table

id | name | address   | 
-----------------------
01 | Chloe| St. Rose  |
02 | Ann  | St. Orchid|

my sql maybe a bit like this : 我的sql可能有点像这样:

create proc sp_search
@name varchar(50),
@address varchar(50)
as
select * from employee where name like '%'+@name+'%' 
and address like '%'+@address+'%'

my .net code for passing parameter like : 我的.net代码,用于传递参数,例如:

Sub show_search_employee()
    With Me
        Dim report As New employee_report
        report.SetDataSource(ds)
        report.SetParameterValue("@name", name.text) //name parameter
        report.SetParameterValue("@address", address.Text) //address parameter
        form_employee_report.crv_employee.ReportSource = report //set report source
    End With
End Sub

my crystal report formula (i just double-click the database field, type '=', and double-click parameter) 我的水晶报表公式(我只需双击数据库字段,键入“ =”,然后双击参数)

{sp_employee_report;1.name} like {?@name} and 
{sp_employee_report;1.address} like {?@address}

the result can be showed if the name parameter and address parameter exactly the value, like if i'd like to show the '01', i must type the name and address 'Chloe' and 'st. 如果name参数和address参数恰好是值,则可以显示结果,就像我想显示'01'一样,我必须输入name和address'Chloe'和'st。 rose'. 玫瑰'。 if i just set the name 'C' or the address 'rose', no value showed. 如果我只是设置名称“ C”或地址“ rose”,则不会显示任何值。 i'd like to set the name parameter just like 'C' or 'Ch' to show the first row, just like the 'Like' function from the sql works. 我想像'C'或'Ch'一样设置name参数以显示第一行,就像sql中的'Like'函数一样。 Thank you for your reply 谢谢您的回复

Note: This is not tested code 注意:这不是经过测试的代码

Try something like this 试试这个

{sp_employee_report;1.name} like "%"+{?@name}+"%" and 
{sp_employee_report;1.address} like "%"+{?@address}+"%"

finally i got the answer.. after long-time searching and browse, the solution is that the crystal report formula (maybe i think) can't accept the '%' for 'like' syntax on our sql parameter that passed to crystal report. 最终我得到了答案..经过长时间的搜索和浏览,解决方案是水晶报表公式(也许我认为)不能接受传递给水晶报表的sql参数上“ like”语法的“%” 。 so i change the '%' to '*' on the formula so it look like : 所以我在公式上将'%'更改为'*',所以看起来像:

{sp_employee_report;1.name} like '*'+{?@name}+'*' and
{sp_employee_report;1.address} like '*'+{?@address}+'*'

i hope this could help anyone that has the same problem like i had 我希望这可以帮助任何遇到与我一样的问题的人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM