ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 23rd, 2004, 11:31 AM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
search with wildcard - newbie question

Hello all,

I am using coldfusion in conjuction with a sql server database. I am trying to recreate a simple search page based on one given to me by an aquaintance and I am having trouble implementing it.

Basically there is a space to type in a job number (name="Job_Number"), then an empty text box to hold a string (name="querystring1"), then two radio buttons, one for "and" (name="querytype" value="and") one for "or" (name="querytype" value="or") and then another empty text box to hold a second string (name="querystring2").

The idea is that a user can search by a job number, or they can search by a keyword, or they can search by two keywords using an 'and' or 'or'.

I have these set up on a page called query submitting to a page called queryResults.

This is the code I have on my queryResults page:

Code:
<cfquery name="q_queryResults" datasource="PLOG">
SELECT *
FROM data_admin.Main_log
WHERE 0=0

    <CFIF #FORM.Job_Number# IS NOT "">
       AND Job_Number LIKE (#FORM.Job_Number#)
    </CFIF>
	
	<CFIF #FORM.querystring1# IS NOT "">
       AND ( upper(trim(Refuge_Literal)||' '||trim(Requestor)||' '||trim(Requestor_Office)||' '||trim(Project_Type)||' '||trim(Map_Type)||' '||trim(Rq_Description) ||' '||trim(Assigned_To)) LIKE upper('%#FORM.querystring1#%')
    </CFIF>
	
    <CFIF #FORM.querystring2# IS "" AND #FORM.querystring1# IS NOT "">
       )
    </CFIF>

    <CFIF #FORM.querystring2# IS NOT "">
       #FORM.querytype# upper(trim(Refuge_Literal)||' '||trim(Requestor)||' '||trim(Requestor_Office)||' '||trim(Project_Type)||' '||trim(Map_Type)||' '||trim(Rq_Description) ||' '||trim(Assigned_To)) LIKE upper('%#FORM.querystring2#%') )
    </CFIF>
	
ORDER BY Date_Assigned DESC, Job_Number DESC

</cfquery>


and then a table that simple displays the results.

I get an error message saying
Quote:
[Macromedia][SQLServer JDBC Driver][SQLServer]'trim' is not a recognized function name.


What am I doing wrong? I would be happy to post more code if that would help.

Or if there is a better way to do this I would love to hear it.

Thanks anyone,
melissa

Reply With Quote
  #2  
Old June 23rd, 2004, 12:51 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
SQL Server doesn't have a trim() function, it has ltrim() and rtrim() which trim to the left and the right of the string, respectively. So you might try:

upper(rtrim(ltrim(Refuge_Literal)))
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old June 23rd, 2004, 12:56 PM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
Hi kiteless! You always come to my rescue

Does the or function work (||) because after I replaced all the trims I got this error:

"[Macromedia][SQLServer JDBC Driver][SQLServer]Line 9: Incorrect syntax near '|'. "

Reply With Quote
  #4  
Old June 23rd, 2004, 04:38 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
|| isn't an OR operation, it is a string concatenation. But it shouldn't throw an error. Are you sure you have the correct number of parenthesis around the functions?

Reply With Quote
  #5  
Old June 23rd, 2004, 04:41 PM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
Well I completely erased everything and started over. It now works but I would love it if there was a simpler way to state it. There must be a shorter version of what I've written?

Here is the final code which works:

Code:
<cfquery name="q_queryResults" datasource="PLOG">
SELECT *
FROM data_admin.Main_log
WHERE del_job = 0
AND 0=0

    <CFIF #FORM.Job_Number# IS NOT "">
       AND Job_Number LIKE ('%#FORM.Job_Number#%')
    </CFIF>
	
	<CFIF #FORM.querystring1# IS NOT "">
       AND Refuge_Literal LIKE ('%#trim(FORM.querystring1)#%') OR Requestor LIKE ('%#trim(FORM.querystring1)#%') OR Requestor_Office LIKE ('%#trim(FORM.querystring1)#%') OR Project_Type LIKE ('%#trim(FORM.querystring1)#%') OR Map_Type LIKE ('%#trim(FORM.querystring1)#%') OR Rq_Description LIKE ('%#trim(FORM.querystring1)#%') OR Assigned_To LIKE ('%#trim(FORM.querystring1)#%')
    </CFIF>

    <CFIF #FORM.querystring2# IS NOT "">
       #FORM.querytype# Refuge_Literal LIKE ('%#trim(FORM.querystring2)#%') OR Requestor LIKE ('%#trim(FORM.querystring2)#%') OR Requestor_Office LIKE ('%#trim(FORM.querystring2)#%') OR Project_Type LIKE ('%#trim(FORM.querystring2)#%') OR Map_Type LIKE ('%#trim(FORM.querystring2)#%') OR Rq_Description LIKE ('%#trim(FORM.querystring2)#%') OR Assigned_To LIKE ('%#trim(FORM.querystring2)#%')
    </CFIF>

ORDER BY Date_Assigned DESC, Job_Number DESC

</cfquery>


thanks,
melissa

Reply With Quote
  #6  
Old June 23rd, 2004, 07:33 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
Can't test this code, but this is a starting point. It is also fairly complex, but unlike your original code, this can easily have additional form fields or database fields added and handled. Basically, SQL is terrible at doing anything beyond basic searching. Most databases now support free text searching, and CF comes with Verity which handles searching a database much more thoroughly.

Code:
<cfquery name="q_queryResults" datasource="PLOG">
SELECT *
FROM data_admin.Main_log
WHERE del_job = 0
AND 0=0

    <CFIF form.Job_Number IS NOT "">
       AND Job_Number LIKE ('%#FORM.Job_Number#%')
    </CFIF>
	
	<cfset formSearchFieldList = "queryString1,queryString2" >
	<cfset targetFieldList = "Refuge_Literal,Requestor_Office,Project_Type,Map_Type,Rq_Description,Assigned_To">
	
	<cfloop index="thisFormField" list="#formSearchFieldList#" delimiters=",">
		<cfif len( trim( form[thisFormField] ) )>
			<cfloop index="thisDBField" list="#targetFieldList#" delimiters=",">
				<cfif listFind( targetFieldList, thisDBField, "," ) eq 1>
					AND
				<cfelse>
					OR
				</cfif>
				#thisDBField# LIKE ('%#trim( form[thisFormField] )#%') 
			</cfloop>
		</cfif>
	</cfloop>	

ORDER BY Date_Assigned DESC, Job_Number DESC

</cfquery>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > search with wildcard - newbie question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway