We help IT Professionals succeed at work.
Get Started

ASP Classic SQL Server LIKE Query not working properly

197 Views
Last Modified: 2016-02-04
Hello All;

The record exist in the database, in both columns, so, it SHOULD state that the record exist.
However, it is not, it is stating that the record does not exist.
Even though it is there.

We are looking at BOTH columns, as the record will exist, ONLY if both columns have the correct information.

The PageList Column, this will have different entries in it like so.

Movies_(Romance) / Movies_(Horror) / Movies_(Comedy) / Movies_(Disney) / Movies_(Drama)

So, that is why I am using the LIKE, so that I can check and see if the "Movies_(Romance)" exist in the column. If not, then add it, else, NOT.

Can someone please shine some light on this?
As I am at my wits end, I do not know what in the world is going wrong.
I got the same code to work in another part of the page, however, I cannot get this one to function.


One last thing.
I ran the same Query inside of SSMS, and it ran perfectly, and like expected, it is just NOT working in the script below.

Carrzkiss

Code:
getTitle = "Movies_(Romance)"
SongName = "Let Me Know"
<%
' Both getTheSong and getTitle are coming from form fields.'
getTheSong = replace(SongName," ","_")
strTerm = "%" & getTitle & "%"

Set sqlUsage = Server.CreateObject("ADODB.Command")
sqlUsage.ActiveConnection=Conn
sqlUsage.Prepared = true
sqlUsage.commandtext="SELECT SongTitle, PageList FROM Songs WHERE SongTitle=? and PageList like ?"
sqlUsage.Parameters.Append sqlUsage.CreateParameter("@SongTitle", adVarChar, adParamInput, 250, getTheSong)
sqlUsage.Parameters.Append sqlUsage.CreateParameter("@PageList", adVarChar, adParamInput, 250, strTerm) 
set rschSong = sqlUsage.execute
if rschSong.eof then
response.write "Does not exist"
else
response.write "Already exist!"
end if
%>

Open in new window

Comment
Watch Question
Author, Web Developer
CERTIFIED EXPERT
Top Expert 2009
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE