Solved

Searching keywords in MS SQL

Posted on 2006-10-27
7
247 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
Independent Software Vendors: 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 138
ejb wildfly example 2 72
Output in PHP throwing alignment of data off issue 12 56
Problems moving Excel files from local drive to server 4 28
This is about my first experience with programming Arduino.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

756 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