Solved

Searching keywords in MS SQL

Posted on 2006-10-27
7
245 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now