473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Site Search Code Help

I'm writing a search for our site and I'm running into a few problems.
When I run the query like this, it runs just fine:

Declare @Keywords varchar(2000)
Select @Keywords = 'modern trial advocacy canada'
Select product_id, name, count(name) hits
FROM estore_products
INNER JOIN sequence
ON estore_products.name like '%' +
Substring(' ' + @keywords + ' ',seq,
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq)
+ '%'
WHERE
seq <= len(' ' + @keywords + ' ') and
Substring(' ' + @keywords + ' ', seq - 1, 1) = ' ' and
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq 0
Group by estore_products.product_id, name
ORDER BY Hits DESC

But when I add another column (for example a column called description)
from the select statement I get this error:

The text, ntext, and image data types cannot be compared or sorted,
except when using IS NULL or LIKE operator.

Long story short, what do I need to do to select more columns for the
final output?

Thanks,
Ryan

Dec 27 '06 #1
4 3054
Hi Ryan

Have you read http://www.sommarskog.se/dyn-search.html ?

John

<Ev******@gmail.comwrote in message
news:11*********************@79g2000cws.googlegrou ps.com...
I'm writing a search for our site and I'm running into a few problems.
When I run the query like this, it runs just fine:

Declare @Keywords varchar(2000)
Select @Keywords = 'modern trial advocacy canada'
Select product_id, name, count(name) hits
FROM estore_products
INNER JOIN sequence
ON estore_products.name like '%' +
Substring(' ' + @keywords + ' ',seq,
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq)
+ '%'
WHERE
seq <= len(' ' + @keywords + ' ') and
Substring(' ' + @keywords + ' ', seq - 1, 1) = ' ' and
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq 0
Group by estore_products.product_id, name
ORDER BY Hits DESC

But when I add another column (for example a column called description)
from the select statement I get this error:

The text, ntext, and image data types cannot be compared or sorted,
except when using IS NULL or LIKE operator.

Long story short, what do I need to do to select more columns for the
final output?

Thanks,
Ryan

Dec 27 '06 #2
Ev******@gmail.com (Ev******@gmail.com) writes:
I'm writing a search for our site and I'm running into a few problems.
When I run the query like this, it runs just fine:

Declare @Keywords varchar(2000)
Select @Keywords = 'modern trial advocacy canada'
Select product_id, name, count(name) hits
FROM estore_products
INNER JOIN sequence
ON estore_products.name like '%' +
Substring(' ' + @keywords + ' ',seq,
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq)
+ '%'
WHERE
seq <= len(' ' + @keywords + ' ') and
Substring(' ' + @keywords + ' ', seq - 1, 1) = ' ' and
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq 0
Group by estore_products.product_id, name
ORDER BY Hits DESC

But when I add another column (for example a column called description)
from the select statement I get this error:

The text, ntext, and image data types cannot be compared or sorted,
except when using IS NULL or LIKE operator.

Long story short, what do I need to do to select more columns for the
final output?
What is the data type of that column? And how does the query with that
column look like?

You would only get this error if you are using the text/ntext/image
data type.

What version of SQL Server are you using? On SQL 2005, there is no
need to use text & co, as there are new data types (n)varchar(MAX)
and varbinary(MAX) which can fit just as much data as text & co,
but which does not have all restrictions of the old types.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 27 '06 #3
I changed the data type and now I have the correct columns being
searched but now I have a new problem. When I search for a program
name, it returns just fine (the first part of the union) but when I
search for a persons name (the latter half of the union) I need it to
return the program's name from estore_products not the name from
crm_contact_publishers. Any ideas on how to get it to output the name
column from estore_products? The product IDs are the same on each
table. TIA
Ryan
My code:

Declare @Keywords varchar(2000)
Select @Keywords = 'zwier' -- Static for now and we'll pass it off
later from vb
Select name, product_id, count(name) hits
FROM estore_products
INNER JOIN sequence
ON estore_products.name like '%' +
Substring(' ' + @keywords + ' ',seq,
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq)
+ '%'
WHERE
seq <= len(' ' + @keywords + ' ') and
Substring(' ' + @keywords + ' ', seq - 1, 1) = ' ' and
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq 0
Group by product_id, name, description
UNION
Select name, estore_product_id, count(name) hits
FROM crm_contact_publishers
INNER JOIN sequence
ON crm_contact_publishers.name like '%' +
Substring(' ' + @keywords + ' ',seq,
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq)
+ '%'
WHERE
seq <= len(' ' + @keywords + ' ') and
Substring(' ' + @keywords + ' ', seq - 1, 1) = ' ' and
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq 0
Group by name, estore_product_id
ORDER BY Hits DESC

Jan 3 '07 #4
Ev******@gmail.com (Ev******@gmail.com) writes:
I changed the data type and now I have the correct columns being
searched but now I have a new problem. When I search for a program
name, it returns just fine (the first part of the union) but when I
search for a persons name (the latter half of the union) I need it to
return the program's name from estore_products not the name from
crm_contact_publishers. Any ideas on how to get it to output the name
column from estore_products?
Could be as easy as?

Select e.name, estore_product_id, count(name) hits
FROM crm_contact_publishers p
JOIN estore_products e ON c.product_id = p.product_id
INNER JOIN sequence
ON crm_contact_publishers.name like '%' +
Substring(' ' + @keywords + ' ',seq,
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq)
+ '%'
WHERE
seq <= len(' ' + @keywords + ' ') and
Substring(' ' + @keywords + ' ', seq - 1, 1) = ' ' and
CharIndex(' ' , ' ' + @keywords + ' ' , seq) - seq 0
Group by name, estore_product_id
ORDER BY Hits DESC

There is a good recommendation for posting queries like this and
that is that you post:

o CREATE TABLE statements for your tables, preferably with
PRIMARY and FOREIGN KEY definitions.
o INSERT statements with sample data.
o The desired output with sample data.

That makes it possible to develop a tested solution. The less information
you post, the wilder the guesses you will be you get in response.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SteveJ | last post by:
All, Can someone help me solve the next step. First of all let me say I'm new to php. I pieced the following code together from samples I found on the net and a book I bought called PHP...
3
by: Carol | last post by:
What's the best way to do a site search of my site? I am using asp and access heavily on a regular ISP google? Or write a bunch of queries? what else is there?
4
by: Miguel Dias Moura | last post by:
Hello, I launched a web site some time ago and i am having problems in making it visible in the search engines. I used a lot of Keywords, not only in text but also in links, page and image...
4
by: gwtc | last post by:
Here is a google search site bookmarklet. This lets you search a certain website using google. What I want is the same thing, but to search a certain geocities site. When you use the current...
25
by: Peter Michaux | last post by:
Hi, There have been a few suggestions for changing the format of the FAQ site to make it easier to maintain. VK suggested and XML procedure. Matt Kruse suggested a wiki. I think something...
71
by: Murray R. Van Luyn | last post by:
Hi, Since I have made changes to my website it's been a complete flop. According to the logs, as soon as visitors have downloaded the index page they are off. I can't figure out why? ...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
7
by: ThunderMusic | last post by:
Hi, Ok, I find myself having a lot of troubles with URL Rewriting and I've seen on the net that in some situations, indexers have difficulty indexing sites because of some flaws in the url...
2
by: tridirk | last post by:
Hi; I am getting a Objceted Expected Error on my forum site. I can't find what is wrong? Line: Char: Error: Object expected Code:0 the site is My SMF Forum
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.