Have you tried  LEN(TRIM("Form.LastName")) ?

-----Original Message-----
From: Bruce Sorge [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 01, 2006 3:43 PM
To: CF-Talk
Subject: Problems with LEN


OK, I have this query:



<cfquery datasource="#Session.DSN#" name="qSearchResults">

            SELECT ContactID, FIrstName, LastName, DateModified

            FROM Contact

            WHERE 0=0

            AND

            <cfif LEN("Form.FirstName") GT 0>

            FirstName

            <cfif Form.searchCriteria IS "exactPhrase">

                        = '#Form.FirstName#'

            <cfelseif Form.searchCriteria IS "allWords">

                        LIKE '%#Form.FirstName#%'

            </cfif>

            </cfif>

            <cfif LEN("Form.LastName") GT 0>

            AND LastName

            <cfif Form.searchCriteria IS "exactPhrase">

                        = '#Form.LastName#'

            <cfelseif Form.searchCriteria IS "allWords">

                        LIKE '%#Form.LastName#%'

            </cfif>

            </cfif>

</cfquery>



I can dump the LEN of firstname and lastname. So if I do not enter anything
in the lastname field and enter something in the firstname field, the len
for firstname is X and the LEN for lastname is 0, so by allrights it should
only do the AND FirstName = "#Form.FirstName# if I select exactPhrase. The
only way it works if I enter something in one field but not the other is if
I select allWords, because it is using the LIKE operator. So why is it that
if I use ExactPhrase it executes the following query:



SELECT ContactID, FirstName, LastName, DateModified

FROM Contact

WHERE 0=0

AND FirstName = 'Bruce'

AND LastName = ' '



LastName should not even be a part of the query if I do not enter anything
into it.



Thanks,





Bruce Sorge










~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:241959
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to