Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 14th, 2005, 07:07 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old March 14th, 2005, 07:52 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
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
Reply With Quote
  #3 (permalink)  
Old March 14th, 2005, 10:04 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: , , .
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..???


Reply With Quote
  #4 (permalink)  
Old March 14th, 2005, 10:40 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
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
Reply With Quote
  #5 (permalink)  
Old March 14th, 2005, 10:57 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: , , .
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

Reply With Quote
  #6 (permalink)  
Old March 14th, 2005, 11:15 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:29 PM.


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