PDA

View Full Version : Can any1 help me by answering questions?


helLO
04-12-2003, 03:55 PM
I'm new at this... Sorry for asking too many questions...

Code 1:
ABC = Replace(ABC, "'", "''")

----------------------------------------------------------------

Code 2:
SQL_Stat = "SELECT * " _
& "FROM Test " _
& "WHERE No LIKE '%" & Replace(ABC, "'", "''") & "%' " _
& "OR Name LIKE '%" & Replace(ABC, "'", "''") & "%' " _

-------------------------------------------------------------------

For code 1: What does <replace> mean and do? What is <ABC, "'", "''"> do? Is it replacing ABC into " " or vice versa? Is this statement a form of declaration?

-------------------------------------------------------------------

For code 2: What is the <replace> for? Does it has the same meaning as the 1st code? What is <%> and <_> for? Is the <&> used there for concatenation purpose? What is the <LIKE> for?

Thanks...

raf
04-12-2003, 08:20 PM
1.
replace(string,"whattoreplace","withwhattoreplace")

so
if
text = "I am smart!"
then
text=replace(text,"smart","stupid") means that text="I am stupid!"

when you write textvalues to a db, you need to replace the single quote with two single quotes. Else the sql statement will error. When you look at the inserted values, you'll see there was only one sinqle quote inserted. So you insert what you actually wanted.
(look at the sticky on top of this forum!!)

You should always use this function on all values for textvariables that you use in a sql statement

2.
_ and & or just a way to link the textvalues that are now spread over several lines (so you don't need to scroll in your code)

SQL_Stat = "SELECT * " _
& "FROM Test " _
& "WHERE No LIKE '%" & Replace(ABC, "'", "''") & "%' " _
& "OR Name LIKE '%" & Replace(ABC, "'", "''") & "%' " _

is the same as

SQL_Stat = "SELECT * FROM Test WHERE No LIKE '%" & Replace(ABC, "'", "''") & "%' OR Name LIKE '%" & Replace(ABC, "'", "''") & "%' " _

I personally use this form:
SQL_Stat = "SELECT * FROM Test WHERE No LIKE '%term1%' OR Name LIKE '%term1%' "
SQL_Stat = replace(SQL_Stat ,"term1",replace(ABC,"'","''"))

But thats just my personal preference !

3.
Like
is an operator. If you use "=" then the value in the evaluate field in the database needs to be identical. If you use "LIKE" you can use wildcards (for instance %)
select * from table where variable='test' returns only records where the value of variable is 'test'
select * from table where variable LIKE '%test%' will also return records that have 'atest' or 'tester' etc have as value for the variable.

david7777
04-14-2003, 08:11 AM
You should check out www.w3schools.com for really good help...
:cool:

dominicall
04-14-2003, 07:49 PM
One of the best resources for learning ASP is the Wrox book: Beginning ASP 3

I've been programming ASP for about 4 years now and still keep it by my side - my trusty companion when I'm programming - LOL

dominicall

Mhtml
04-15-2003, 05:46 AM
I'd like to call your attention to section 2 of the posting guidelines (http://www.codingforums.com/postguide.htm).

helLO
05-13-2003, 11:04 AM
Thanks for the help...

:)