Results 1 to 2 of 2


  1. #1
    Join Date
    Dec 1969


    i have a DB with table named Products. pCategory lists several names of teams of varing leagues (NBA, NFL, MLB, etc...) I want a table to display only the NBA teams. I have a field named pGroup which has NBA, MLB, etc... for each team. How can I display all fields where pGroup="NBA." I thought the code would work below, but it didn&#039;t. thanks.<BR><BR><BR>&#060;% sql_getProducts = "SELECT DISTINCT pCategory WHERE pGroup="NBA" FROM products"

  2. #2
    Join Date
    Dec 1969

    Default Nothing to do with SQL...

    Look, in most computer languages--and *certainly* including VBScript which you are coding in--a literal string (sometimes also called a [i]string constant[/b]) begins with a quote mark and ends with the first subsequent quote mark.<BR><BR>So look at the first literal string in your code:<BR><BR>&#060;% <BR>sql_getProducts = [hl="yellow"]"SELECT DISTINCT pCategory WHERE pGroup="[/hl]NBA" FROM products"<BR>%&#062;<BR><BR>And then poor VBScript is left to figure out what the heck you mean by <BR> NBA" FROM products"<BR><BR>Now, VBScript *DOES* have an "escape mechanism" that allows you to embed a quote inside of a literal string: Use a pair of embedded quotes to so signify. So you *could* have written your code thus:<BR><BR>&#060;% <BR>sql_getProducts = "SELECT DISTINCT pCategory WHERE pGroup=[hl="lightgreen"]""[/hl]NBA[hl="lightgreen"]""[/hl] FROM products"<BR>%&#062;<BR><BR>However, there&#039;s a simpler way: *MOST* databases accept (and ANSI SQL specifies) apostrophes as the correct characters for delimiting a literal string in SQL. So:<BR><BR>&#060;% <BR>sql_getProducts = "SELECT DISTINCT pCategory WHERE pGroup=[hl="lightgreen"]&#039;[/hl]NBA[hl="lightgreen"]&#039;[/hl] FROM products"<BR>%&#062;<BR><BR>It&#039;s important to understand that, to VBScript, your SQL code is just a bunch of random characters. VBS doesn&#039;t know or care what&#039;s in that string. It&#039;s YOUR job to be sure that the resulting string makes sense to the database&#039;s SQL engine. So start learning NOW to DEBUG DEBUG DEBUG.<BR><BR>At a minimum, write out the SQL you are attempting to use. Not a big deal in this instance, but a life saver when things get more complex. So:<BR><BR>&#060;% <BR>sql_getProducts = "SELECT DISTINCT pCategory WHERE pGroup=&#039;NBA&#039; FROM products"<BR><BR>Response.Write "DEBUG SQL: " & sql_getProducts & "&#060;HR&#062;"<BR>%&#062;<BR><BR>Naturally, you can comment out the debug code after things start working.<BR><BR>Oh...and find a *GOOD* tutorial on programming, preferably on programming VBScript.<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