Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

ASP and SQL

I'm trying to run a SQL statment, mixed with some VBScript. HEre is my code:

DIM mySQL
mySQL = "select  empid from a_employee" & _
        "where empfirstname + ' ' + emplastname = " & " ' " & Tim Tester " ' "
MyConn.Execute mySQL

When I try and submit the asp page, it comes back and tells me that it doesn't like the + sign. If I were doing this in a SQL Query window, it works fine...see my regular sql statement below. But for some reason, ASP doesn't like it.

select  empid, empfirstname, emplastname from a_employee
where empfirstname + ' ' + emplastname = 'Tim Tester'

Any ideas?
0
ONYX
Asked:
ONYX
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
If that's an exact copy and paste of what you have, then you are missing a space at the beginning of "where" or the end of "a_employee" and I assume this:
& Tim Tester " ' "
is actually a variable used here.  Otherwise, I'm sure you know it should look like
& "Tim Tester" & "'" (although, there's no need to seperate out the quotes from the text).

If you can, have it echo back the SQL line, then cut and paste it into the SQL Query area to execute it outside the script.  It may shed some light on your problem.
0
 
JuergenHartlCommented:
If you are using an Access database create the query in access and have a look at the SQL statement inj SQLView.
0
 
FaircoCommented:
leew answered the most interesting part of the query. But there's another error. You need to add an additional space in the text at the line break!
So the following line
  "select  empid from a_employee" & _
should be
  "select  empid from a_employee " & _

This is very important, because your text currently merges the "a_employee" and the "where" phrase together, resulting "a_employeewhere", which is not understood by the SQL engine.
I also recommend to echo back the "mySQL" variable for debugging. In ASP use the "Response.write mySQL" statement to achieve this.
(By the way, why is this problem related to any hardware?)
0
 
ONYXAuthor Commented:
Thanks for all the replies. Indeed, it was a space that I was missing. Sorry for posting this in the 'hardware' section...my mistake.
0

Featured Post

Lessons on Wi-Fi & Recommendations on KRACK

Simplicity and security can be a difficult  balance for any business to tackle. Join us on December 6th for a look at your company's biggest security gap. We will also address the most recent attack, "KRACK" and provide recommendations on how to secure your Wi-Fi network today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now