Solved

Searching keywords in MS SQL

Posted on 2006-10-27
7
243 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 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

15 Experts available now in Live!

Get 1:1 Help Now