Crystal Report Passing Stored Procedure Parameter from “Like” Sql

纵饮孤独 提交于 2019-12-24 14:04:38

问题


I have problems in passing stored procedure parameter to crystal report. 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.

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 :

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 :

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. rose'. if i just set the name 'C' or the address 'rose', no value showed. 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. Thank you for your reply


回答1:


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}+"%"



回答2:


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. 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



来源:https://stackoverflow.com/questions/22439261/crystal-report-passing-stored-procedure-parameter-from-like-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!