Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 14th, 2005, 07:07 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default Replacing a character from string

Hello!

I need to remove a specific character from a feild in sql query. Means I need to use REPLACE function on sql query to match with specific criteria.

Something like this,

FULL_NAME = "sun is resing" (Database field name and it's vlaue)


sql = "select * from customers where REPLACE(FULL_NAME, "s", "") = 'un i reing'

Any idea, Any help will really be appriciated

 
Old March 14th, 2005, 07:52 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

I have never used replace in a query (not to say icant be done). May I suggest another method. To achieve this I tend to use conditions, either to execute different queries (1), or to build a query(2).

Eg (1)
If request.form("currentStatus") = "True" then
sql = "UPDATE serviceCallDocs SET approved=0 WHERE..."
ELSEIF request.form("currentStatus") = "False" then
sql = "UPDATE serviceCallDocs SET approved=1 WHERE..."
END IF

Or (2)
sql = "UPDATE tblName SET "
if [something1] = [something1] then
     sql = sql & " FieldName "
else
     sql = sql & " someOtherFieldName "
end if
sql = sql & " = "
if [something2] = [something2] then
     sql = sql & " someValue "
Else
     sql = sql & " someOthervalue "
End if
sql = sql & " WHERE... "
response.write sql & "==<br>"

Wind is your friend
Matt
 
Old March 14th, 2005, 10:04 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

Thanks for your reply Matt.
But actually this is a search program with 500+ records and what I need is,

When I search it should do a checking of word ‘s’ or removing the word ‘s’ if one was added
Such as I search for “car”. It also includes “cars”
OR
search for "cars". It also includes "car"

Any ideas..???


 
Old March 14th, 2005, 10:40 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

I would still build queries based on conditions using the LIKE operator.

;;;;I search for “car”. It also includes “cars”
sql = "SELECT someField FROM tblename WHERE somefield LIKE '%car%'"
Would do it, however it would also pull all other records starting with the letters car as well.

;;;search for "cars". It also includes "car"
Not so strait forward. I would create a table of words and thier aliases. Query this table on the key word (cars) then get all the aliases you have defined that are equal to your key word and search for these.

Wind is your friend
Matt
 
Old March 14th, 2005, 10:57 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

Hmm, how about this
;;;search for "cars". It also includes "car"
check the last character of keyword and if it contain "s" in last simply remove it. So the condition will become exactly as first one. - Thanks

 
Old March 14th, 2005, 11:15 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

If that works, great - but would it?

I guess if all plural names became singular after dropping the s it would work. What about a search for pennies, dropping the s wouldnt give us all results for penny.

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing multiple characters in a string philboparker BOOK: XSLT Programmer's Reference, 2nd Edition 0 May 20th, 2008 04:38 PM
replacing numbers in a string cole SQL Server 2000 4 April 2nd, 2007 04:24 PM
Replacing characters in a string semilemon C# 2005 2 June 16th, 2006 11:31 PM
Replacing a character with an integer sereneabraham79 VS.NET 2002/2003 2 September 18th, 2004 12:34 AM
Replacing Text with a String in a Form newgeek Beginning VB 6 2 August 14th, 2003 12:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.