我在水晶报告中使用查询,如:
if({?User Name}) <>"ALL"
then
{COMN_USER_RESP_LINK_T.APPL_USER_NAME}={?User Name}
else
{COMN_USER_RESP_LINK_T.APPL_USER_NAME} ={COMN_USER_RESP_LINK_T.APPL_USER_NAME}
and
{COMN_USER_RESP_LINK_T.ENABLED}="Y"
这是sql中的实际查询:
SELECT
C.APPL_USER_NAME,
A.RESP_NAME,
B.MENU_NAME,
B.DESCRIPTION,
B.MODULE_NAME,
C.APPL_RESP
FROM COMN_RESPONSIBILITY_T A,
COMN_RESP_MENU_LINK_T B,
COMN_USER_RESP_LINK_T C
WHERE A.COMP_CODE = B.COMP_CODE
AND B.COMP_CODE = C.COMP_CODE
AND C.COMP_CODE = A.COMP_CODE
AND A.RESP_NAME = B.RESP
AND C.APPL_RESP = A.RESP_NAME
AND B.ENABLED = 'Y'
AND C.APPL_USER_NAME = c.APPL_USER_NAME
CASE @ACCT_CODE_FROM
WHEN 'ALL' THEN C.APPL_USER_NAME
ELSE @ACCT_CODE_FROM
END
ORDER BY APPL_USER_NAME,
RESP_NAME
我应该在参数字段(?用户名)中选择用户名,如果我选择ALL,那么我必须显示所有记录({COMN_USER_RESP_LINK_T.APPL_USER_NAME}
)
上面的查询是否正确?
答案 0 :(得分:0)
我可能会将其改为:
SELECT C.APPL_USER_NAME, A.RESP_NAME, B.MENU_NAME, B.DESCRIPTION,
B.MODULE_NAME, C.APPL_RESP
FROM COMN_RESPONSIBILITY_T A
INNER JOIN COMN_RESP_MENU_LINK_T B ON A.COMP_CODE = B.COMP_CODE
AND A.RESP_NAME = B.RESP
INNER JOIN COMN_USER_RESP_LINK_T C ON B.COMP_CODE = C.COMP_CODE
AND C.APPL_RESP = A.RESP_NAME
WHERE ((@ACCT_CODE_FROM = 'ALL') AND (B.ENABLED = 'Y'))
OR (C.APPL_USER_NAME = @ACCT_CODE_FROM)
ORDER BY APPL_USER_NAME, RESP_NAME
这将为您提供以下任何一项的详细信息:
答案 1 :(得分:0)
我不读你的代码因为它很脏!但我认为你可以在水晶报告中使用SelectionFormula。当然你可以在代码中设置它:
crystalReportViewer1.SelectionFormula ="(({?User Name}= 'ALL') AND ({B.ENABLED} = 'Y'))
OR ({C.APPL_USER_NAME} = @ACCT_CODE_FROM)"