I'm pretty useless in SQL, but I have to write a stored procedure for a very simple keyword phrase search.
I'm trying to make a simple choice in Name - using, for example,% keyword%, - then another select on Description -same keyword- and join (union), which selects 2.
However, I get an error message:
The ntext data type cannot be selected as DISTINCT because it is not comparable.
I tried to use UNION ALL , but in some cases returned duplicate lines (depending on the keyword / phrase).
I also tried to figure out how to use temporary tables and choose a different one from this, but that I was really confused.
Rules:
- I can not change the data type
- I need the lines from select to "Name" to be above the lines from the one selected in "Description"
- I can use only 1 stored procedure and cannot change the data adapter, since I connect it to a system in which I do not control.
Additional Information:
Columns of tables (important 2 that I work with are name and description):
ProductId int Name varchar(255) Introduction varchar(255) Description ntext Material ntext Colour varchar(255) Active bit Dimensions varchar(255) Photo varchar(255) Price decimal(10, 2) DisplayOrder int ProductReference varchar(255) CategoryId int FriendlyURL varchar(1000)
SQL:
(SELECT Products.ProductId, Name, Introduction, Description, Active, Material, Colour, Dimensions, Photo, Price, DisplayOrder, FriendlyURL, ProductReference, Categories_Products_Lookup.CategoryId FROM Products INNER JOIN Categories_Products_Lookup ON Products.ProductId = Categories_Products_Lookup.ProductId WHERE Active = 1 AND tProduct.Name like '%'+@Keyword+'%') UNION (SELECT Products.ProductId, Name, Introduction, Description, Active, Material, Colour, Dimensions, Photo, Price, DisplayOrder, FriendlyURL, ProductReference, Categories_Products_Lookup.CategoryId FROM ProductsINNER JOIN Categories_Products_Lookup ON Products.ProductId = Categories_Products_Lookup.ProductId WHERE Active = 1 AND Products.Description like '%'+@Keyword+'%')
Any help received from the table of various rows would really be appreciated. Also, explaining to me how Lyman would be great. :)