Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenate string with single aprostrophes 2

Status
Not open for further replies.

richey1

Technical User
Oct 5, 2004
184
GB
Hi

I'm trying to build up a select statement in asp using the IN operator. I've got

SchText = request.form("cat")
if len(SchText)=0 then
SchText = "'" & SchText & "' "
Flag = Flag + 1
end if

and then the select statement (shown further below) which doesn't work because it may say
Select * From members WHERE BusinessName like '%%%%%%' AND Keywords1 like '%%%%%%' AND Cat IN ('Other , Accountants') AND DateEst >= '1899' AND DateEst <= '2005'

when it should be IN ('Other' , 'Accountants')

any ideas ?

also
if len(SchText)=0 then
I need to use a wildcard to say any category

thanks
ian

select statement
----------------
sqlstmt="Select * From members WHERE BusinessName like '%%" & SchTitle & "%%' "
sqlstmt=sqlstmt & " AND Keywords1 like '%%" & SchKeywords & "%%' "
sqlstmt=sqlstmt & " AND Cat IN ('" & trim(schText) & "')"
sqlstmt=sqlstmt & " AND DateEst >= '" & SchDateStart & "' "
sqlstmt=sqlstmt & " AND DateEst <= '" & SchDateEnd & "'"
 
try this:

SchText = request.form("cat")
if len(SchText)=0 then
SchText = "'" & SchText & "' "
[red]SchText = Replace(SchText,",","','")[/red]
Flag = Flag + 1
end if

here we are replacing a , with ','

-DNG
 
If you would PLEASE post code like that in a code box it would be MUCH easier to read. It's very difficult to tell the difference between quotes and apostrophes in the normal font used here, especially in code when you're doubling and nesting them. Isn't this much easier to read?
Code:
SchText = request.form("cat")
if len(SchText)=0 then 
  SchText = "'" & SchText & "' "
  SchText = Replace(SchText,",","','")
Flag = Flag + 1
end if
You can also indent properly in code boxes.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
thanks very much...........

yes much easier to read, not sure how you do the code box but I'll find out................sorry
 
no problem...glad to be of help...in order to put it in the code box just use CODE and /CODE in the beginning and ending of your code...you need to put those around square brackets...also check the link Process TGML in this forum to see more...

-DNG
 
I hate to says this DNG, but I didn't think you knew how to do code tags. That post was primarily directed to you. You post a lot of good responses, but you never use code tags, and some of them are hard to read, for the reasons I mentioned above.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Tracy,

thanks for pointing this out...although i use code tags sometimes, from now on i will make sure that i use them all the time...

-DNG
 
Thanks DNG. I know it can be a pain sometimes, but it does make the code a lot easier to read. If you don't like the separate box, try using the [&#91;]tt] and [&#91;]/tt] tags instead, like this:
[tt]this is in tt tags
indenting works
apostrophes and quotes can be told apart "''"
[/tt]

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top