Solved

Searching keywords in MS SQL

Posted on 2006-10-27
7
248 Views
Last Modified: 2010-04-16
I need to be able to search for keywords in an MS SQL database which I'm able to do except the keywords are encapsulated in brackets which I would like to include in my search. For example, here is how I'm doing it now...

$sqlquery="SELECT * FROM HISTORY WHERE DESCRIPT LIKE '%$wo_id%';";
$results=mssql_query($sqlquery);
$row=mssql_fetch_array($results);

where wo_id is the keyword I'm searching for. The problem with this is, the number could come up in the results from a row that I don't want to include. The problem I have run into is the table the data is stored in doesn't have a column for the id number. The number is in the description like this [4567]. How do I do the above code but also include the brackets. I've tried escaping them or setting them in a variable first but it isn't working for me.

Thanks.
0
Comment
Question by:schnazzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:hclgroup
ID: 17820962
You have to escape it like this

select * from Customers where Companyname like '%[[test]]%'

You have to replace [ with [[ and ] with ]]
0
 

Author Comment

by:schnazzer
ID: 17821134
just as a test, here is what I tried...

SELECT * FROM HISTORY WHERE DESCRIPT LIKE '%[[100]]%'

its still pulling more than what I'm looking for. in fact, in my query, I'm pulling data that doesn't even contain [100] in it.

for example..here is a row that comes up

CANCELLED: WS#[]
0
 

Author Comment

by:schnazzer
ID: 17821246
ok, so I'm doing something wrong.... I'm getting results based on individual characters in my query, for example, doing a search for [1024] lists items similar to my example below...

CANCELLED: WS#[]
CANCELLED: WS#[1]
CANCELLED: WS#[2]
CANCELLED: WS#[4]
CANCELLED: WS#[1024]
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:hclgroup
ID: 17821592
My mistake

replace [ with [[] and ] with []]


E.g. SELECT * FROM HISTORY WHERE DESCRIPT LIKE '%[[]100[]]%'
0
 
LVL 4

Accepted Solution

by:
hclgroup earned 350 total points
ID: 17821645
My mistake again

My mistake

replace [ with [[] and ] with ]


E.g. SELECT * FROM HISTORY WHERE DESCRIPT LIKE '%[[]100]%'
0
 

Author Comment

by:schnazzer
ID: 17821761
Interesting,

Thanks, that worked....
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 17821855
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP/VB email question 4 72
$_GET call between URL 3 70
SQL Server Database Inventory 7 30
Notepad++ Question 11 28
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question