ONYX
asked on
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are using an Access database create the query in access and have a look at the SQL statement inj SQLView.
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?)
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?)
ASKER
Thanks for all the replies. Indeed, it was a space that I was missing. Sorry for posting this in the 'hardware' section...my mistake.