?
Solved

How can I properly query SystemIndex when there are spaces?

Posted on 2014-10-03
5
Medium Priority
?
196 Views
Last Modified: 2015-07-22
Hi!

I have a CLR function that I reference from SQL to carry out full-text searches. The problem I'm having is that the path where the documents reside contains a space i.e. "C:\My Documents\Information". When I place the call I receive no hits. Yet, if I carry out the sample call with a path that contains no spaces i.e. "C:\MyDocuments\Information" I receive a slew of responses.

My query to SystemIndex is formatted like so:

"SELECT System.FileName, System.ItemPathDisplay, System.DateModified FROM SystemIndex WHERE SCOPE = '" + Scope + "' AND CONTAINS('" + Contains + "')"

Open in new window


Does anybody know what I can do to get around this issue. All the examples I find online refer to a path that have no spaces, but client setups vary across the board and we can't enforce that as a rule.

Please help.
0
Comment
Question by:PlawCoder
[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
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40359606
AND CONTAINS('" + Contains.Replace(" ", "") + "')"
0
 

Author Comment

by:PlawCoder
ID: 40359613
The issue here is the SCOPE portion of the query. The path is the one that contains spaces.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40359625
The solution is to replace space with an empty string . . . you can do that on the scope instead.
0
 

Author Comment

by:PlawCoder
ID: 40359641
Thanks Kyle.

But I can't effectively replace "C:\My Documents\Information" with "C:\MyDocuments\Information". That would yield an entirely different path, which doesn't even exist in my directory.

Perhaps I'm not understanding your statement.
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 40359662
Try the following:
string.Format("SELECT System.FileName, System.ItemPathDisplay, System.ItemType, System.Size, System.ItemDate, System.DateModified FROM " +
" myserver.systemindex WHERE SCOPE='{1}' AND" + 
" System.FileName LIKE " +  " '%{0}%'"
, searchString, searchLocation);

Open in new window

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
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 …

718 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