• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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