Solved

How can I properly query SystemIndex when there are spaces?

Posted on 2014-10-03
5
93 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
  • 3
  • 2
5 Comments
 
LVL 39

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 39

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 39

Accepted Solution

by:
Kyle Abrahams earned 500 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

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 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

18 Experts available now in Live!

Get 1:1 Help Now