<% If Trim(rsProdDetail("prodrelatedBooks1"))

Results 1 to 4 of 4

Thread: <% If Trim(rsProdDetail("prodrelatedBooks1"))

  1. #1
    Kevin Guest

    Default <% If Trim(rsProdDetail("prodrelatedBooks1"))

    SQL 2000<BR>Hi everyone,<BR>I have a table with a field in that contains (as an example) A,B,C,D,E, now<BR>what I am tring to do is have this statement in the above instance pickup on<BR>every field that contains an A.<BR>This does not work:<BR>&#060;% If Trim(rsProdDetail("prodrelatedBooks1")) = "%A_%" Then %&#062;<BR><BR>This works if the field only contains an A &#060;% If<BR>Trim(rsProdDetail("prodrelatedBooks1")) = "A" Then %&#062;<BR><BR>This<BR><BR>&#060;% If Trim(rsProdDetail("prodrelatedBooks1")) LIKE "A" Then %&#062;<BR><BR>gives me an error message "<BR>Microsoft VBScript runtime error &#039;800a0023&#039;<BR>Sub or Function not defined<BR>/Store_Front/detail.asp, line 536"<BR><BR>Any input would be great.<BR><BR>Kindest regards,<BR>Kevin<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Ummm...this is pretty basic...

    ...you seem to be getting confused about when you are using SQL syntax and when you need to use VBScript.<BR><BR>I shall hope and assume this is just a case of getting your mind set on SQL and forgetting that you are now working in VBS. Or trying to do in VBS what you could/should be doing in SQL.<BR><BR>VBScript does *NOT* support the notion of "wild cards" in strings *EXCEPT* in Regular Expressions (new with version 5 of VBScript). And then such wild card usage looks *nothing* like the way SQL does it. But for something this simple, you don&#039;t need a regular expression.<BR><BR>Now, you mention you are using SQL Server 2000. And you say:<BR>"I have a table with a field...have this statement...pickup on<BR>every field that contains an A."<BR><BR>So *DO* you want to have SQL do this, before the records are even returned to ADO and VBScript? If so, why are you trying to write VBScript code to do it?<BR><BR>Or, if you want to do this after the records are already retrieved, then why are you trying to use SQL-like syntax?<BR><BR><BR>

  3. #3
    Sreedharan Guest

    Default RE: <% If Trim(rsProdDetail(

    Like Bill says, you seem to be pretty confused about whether you are coming or going!<BR><BR>OK, first lets assume that you are using VBScript:<BR><BR>Then<BR>If Instr(1,UCase(Trim(rsProdDetail("prodrelatedBooks1 "))),"A") &#062; 0 Then<BR> &#039; You *do* have the letter A in your string.<BR>End If<BR>The above assumes that you are not bothered about the case. If you are, then read up on Instr. That would be good homework.<BR><BR>Second, let us assume that you actually want to do this in SQL (which is the preferred method, unless you want to do other stuff with the retrieved data, beyond the basic stuff above)<BR><BR>Select YourField From YourTable Where Upper(YourField) Like &#039;%A%&#039;<BR><BR>Note that you do not require the "Upper" function if your server is set to be case-insensitive.<BR><BR>Next time send your questions to the normal ASP Q&A

  4. #4
    Join Date
    Dec 1969

    Default Nice of you...

    ...to answer him. I probably should have done so, but he also posted in the Moderated Advanced and I admit I was wondering why he thought this question deserved being crossposted in two advanced forums.<BR><BR>Ah, well... See my comments about "the hardest part of ASP" in this message:<BR>http://www.aspmessageboard.com/forum/asp.asp?M=271278&P=1&F=20<BR><BR>This poor guy obviously has walked straight into that "hardest part."<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts