向ColdFusion查询添加AND语句

时间:2018-08-24 15:36:38

标签: coldfusion

我正在尝试添加 AND ActiveFlag ='Y'(与CommissionRoleCode在同一表中的值),但是我所有的尝试都将其制止或被忽略。有人愿意帮助吗?

感谢您的时间!

<cfparam name="attributes.Address" default="">
<cfparam name="attributes.CommitteeID" default="0">
<cfparam name="attributes.AddressListName" default="">

<cfif Len(Trim(attributes.CommitteeID)) EQ 0>
    <cfset attributes.CommitteeID = 0>
</cfif>

<cfif Len(Trim(attributes.Address))>
    <cfset result = "">
    <cfloop list="#attributes.Address#" index="i">
        <cfif Refind("\[{1}.+\]{1}", i)>
            <!---looking for the 'ALL' member type to grab all categories--->
            <cfif i EQ "[ALL]">
                <cfset l_where = "a.CommitteeRoleCode IS NOT NULL AND c.EmailAddress IS NOT NULL">
            <cfelse>
                <cfset l_where = "a.CommitteeRoleCode=#Chr(39)##ReReplace(i, "\[|\]", "", "ALL")##Chr(39)# AND c.EmailAddress IS NOT NULL">
            </cfif>

            <cfquery datasource="#application.datasource#" name="MemberTypeEmails">
                Select c.EmailAddress
                from (Committee_Role_Ref as a Inner Join Committee_Member as b on a.CommitteeRoleCode=b.CommitteeRoleCode)
                    Inner Join Contact as c on b.ContactID=c.ContactID
                Where #ReReplace(l_where, "\'\'", "'", "ALL")#
                    AND b.CommitteeID=#attributes.CommitteeID#
            </cfquery>
            <cfloop query="MemberTypeEmails">
                <cfif ReFind("[^#chr(13)##chr(10)##chr(9)##chr(32)#]@{1}.+\..+", EmailAddress)>
                    <cfif Len(Trim(result))>
                        <cfset result = result & "," & EmailAddress>
                    <cfelse>
                        <cfset result = EmailAddress>
                    </cfif>
                </cfif>
            </cfloop>
        <cfelseif ReFind(".+@{1}.+\..+", i)>
            <cfif Len(Trim(result))>
                <cfset result = result & "," & i>
            <cfelse>
                <cfset result = i>
            </cfif>
        </cfif>
    </cfloop>

    <cfset "caller.#attributes.AddressListName#" = result>
</cfif>

1 个答案:

答案 0 :(得分:0)

您说您正在尝试添加AND ActiveFlag ='Y'(与CommissionRoleCode在同一表中的值)。但是,值CommissionRoleCode出现在两个表中,由于这一部分查询,我知道这一点

a.CommitteeRoleCode = b.CommitteeRoleCode

我的建议是找出ActiveFlag真正位于哪个表中,然后在查询中相应地以a作为前缀。或b。即

AND a.ActiveFlag = 'Y'

AND b.ActiveFlag = 'Y'

然后将AND子句放在以下指示的位置。但是,如果您需要更多帮助,还应该发布您收到的错误消息。

            <cfquery datasource="#application.datasource#" name="MemberTypeEmails">
                Select c.EmailAddress
                from (Committee_Role_Ref as a Inner Join Committee_Member as b on a.CommitteeRoleCode=b.CommitteeRoleCode)
                    Inner Join Contact as c on b.ContactID=c.ContactID
                Where #ReReplace(l_where, "\'\'", "'", "ALL")#
                    AND b.CommitteeID=#attributes.CommitteeID#
                    -- AND a. or b. ActiveFlag goes here 
                    AND a.ActiveFlag = 'Y'
            </cfquery>