WHERE clause in an EXCEL query?

Results 1 to 4 of 4

Thread: WHERE clause in an EXCEL query?

  1. #1
    PGG Guest

    Default WHERE clause in an EXCEL query?

    Is it possible to have a where clause in a SQL statement querying an Excel spreadsheet. I can do a "Select * from [Sheet1$]" and I want to limit the recordset returned by using a WHERE clause.<BR><BR>Thanks for any help.<BR><BR>PGG

  2. #2
    PGG Guest

    Default RE: WHERE clause in an EXCEL query?

    I get an "Unspecified error" message when I use this SQL statement:<BR>sql = "SELECT * FROM [db$] WHERE ([db$]![Unit ID] = unitID)"<BR><BR>Any idea why? Is my syntax correct?

  3. #3
    PGG Guest

    Default Bill , pls help

    I fixed my sql statement and I don&#039;t get any more error messages, but when I response.write the recordset returned I got all the records in my Excel spreadsheet. There should only be one.<BR><BR>Here is my SQL: "Select * from [db$] where UnitID=id". Iam getting the correct value of id from request.querystring. <BR><BR>I don&#039;t know what is going on. Pls help. Thank you.

  4. #4
    Join Date
    Dec 1969

    Default EVERYTHING inside quotes...

    is left UNCHANGED by VBScript.<BR><BR>So look at that line again:<BR><BR>&#060;%<BR>sql = "SELECT * FROM [db$] WHERE ([db$]![Unit ID] = unitID)"<BR>%&#062;<BR><BR>Remember what I said. <BR><BR>Now, *how* are you trying to get a particular id of some unit put into that code? Hmmm??? <BR><BR>"Why I just put something into the variable named unitID."<BR><BR>Oh? Like<BR><BR>&#060;%<BR>unitID = 7<BR>%&#062;<BR>or, more likely, <BR>&#060;%<BR>unitID = Request("someField")<BR>%&#062;<BR><BR>Good. But you still didn&#039;t answer the question. HOW does THAT value get put into the STRING<BR>&nbsp; &nbsp; &nbsp; "SELECT * FROM [db$] WHERE ([db$]![Unit ID] = unitID)"<BR>???<BR><BR>Do you see ANY PART of that which is not inside the quote marks? Hmmm???<BR><BR>So is there ANY PART of that which can or will be changed by changing the value of the variable that just HAPPENS to be named unitID?<BR><BR>The answer is short and sweet: NO!<BR><BR>So, now, let&#039;s try again:<BR><BR>&#060;%<BR>sql = "SELECT * FROM [db$] WHERE [Unit ID] = " & unitID<BR>%&#062;<BR><BR>See the REALLY REALLY HUGE DIFFERENCE there? It might not look like much difference, but it&#039;s truly tremendous! All of a sudden, you are *appending* the value of the variable named unitID INTO THE STRING thate will be sent off to the DB.<BR><BR>And, if you would now do <BR><BR>&#060;%<BR>Response.Write "&#060;HR&#062;" & sql & "&#060;HR&#062;"<BR>%&#062;<BR><BR>You would see that, indeed, the value of unitID is in the SQL to be used.<BR><BR>Hokay?<BR><BR>So remember the rule:<BR><BR>EVERYTHING INSIDE QUOTES IS A STRING. <BR><BR>Substitutions do *not* automatically happen. Period.<BR><BR>If your tutorial ASP book didn&#039;t drive that home 5 times harder than I just did, then it&#039;s time to get a new book. Period.<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