• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

SQL inside VBScript using LIKE on multiple fields

Hi Experts

I am using SQL within VBSCRIPT of a Data Access page which successfully selects the appropriate records based on criteria entered in a text box (named 'criteria') on a page.  

I need to ammend this SQL somehow so that it looks in another field aswell [Problem_Description] but I have no idea how to do this - what I am finding complictaed is the quotes and possibly parenthesis that are needed (and where they go).

This code currently works well for searching the [Company_Name] field.

-----------------------
SearchCN = "INSERT INTO tbl_Results (ID, Company_Name ) " & _
      "SELECT ID, Company_Name " & _
      "FROM tbl_Main WHERE Company_Name LIKE '%" & criteria.value & "%" & "'"
      MSODSC.Connection.Execute SearchCN
-----------------------

Can anyone shed some light onto how this needs to be ammended so it will also search the [Problem_Description] field in the same way i.e. the wirldcards? Many thanks in anticpation...
0
itmanwestermo
Asked:
itmanwestermo
  • 3
  • 2
1 Solution
 
tbsgadiCommented:
Hi ,
Try this
SearchCN = "INSERT INTO tbl_Results (ID, Company_Name,Problem_Description ) " & _
     "SELECT ID, Company_Name,Problem_Description " & _
     "FROM tbl_Main WHERE( Company_Name LIKE '%" & criteria.value & "%" ) or ( Problem_Description LIKE '%" & criteria.value & "%" ) & "'"
     MSODSC.Connection.Execute SearchCN

Good Luck!

Gary
0
 
flavoCommented:
I think that was a little off

SearchCN = "INSERT INTO tbl_Results (ID, Company_Name,Problem_Description ) " & _
    "SELECT ID, Company_Name,Problem_Description " & _
    "FROM tbl_Main WHERE( Company_Name LIKE '%" & criteria.value & "%'  ) or ( Problem_Description LIKE '%" & criteria.value & "%' )"

Dave
0
 
tbsgadiCommented:
Thanks Dave
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
flavoCommented:
"'' No & Worries "''" & "'''"

I hate them damn things!
0
 
itmanwestermoAuthor Commented:
Thank you Dave that was absolutely perfect!  Points are yours....  Thanks to Gary for trying also.

Very happy now :D thank you
0
 
flavoCommented:
Gary,

Please seee here...

http:Q_21426812.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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