Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 TRANSFORM VARIABLE - ADD OPERATOR OR

Author  Topic 

simpleusers
Starting Member

4 Posts

Posted - 2015-05-01 : 12:44:32
ALTER PROCEDURE

@Product = ' 'ORANGE LEMON' BANANA APPLE 'PEACH PEAR' '

AS

-- I WANT TRANSFORM THE WORDS

@PRODUCT = 'ORANGE LEMON' OR BANANA OR APPLE 'PEACH PEAR'


SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, @PRODUCT)
GO

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-05-01 : 13:31:13
I think we are going to need to see more data examples plus expected output. I don't understand the pattern for what you have posted.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-05-02 : 02:52:49
quote:
Originally posted by simpleusers

@PRODUCT = 'ORANGE LEMON' OR BANANA OR APPLE 'PEACH PEAR'



Should that be

@PRODUCT = 'ORANGE LEMON' OR BANANA OR APPLE OR 'PEACH PEAR'

?

My thought is that you could convert the spaces "within" quotes to some other temporary character (not included in the text), then change all spaces to " OR ", and then convert the temporary character back to space.
Go to Top of Page

simpleusers
Starting Member

4 Posts

Posted - 2015-05-02 : 17:15:25
it seems to me an excellent idea , and can help me how can I do this ?
thank you
Go to Top of Page

simpleusers
Starting Member

4 Posts

Posted - 2015-05-02 : 17:17:16
Hello tkizer, I will try better explain.

I have a text box on a web application that allows the user to type what words they want to look. In the first version of the web application the user wrote the words he wanted and was wanted on the table by CONTAINS various words with the OR operator . What I wanted now was to allow the user to write several words, but with a particularity . The words that were inside '' was like a word.

I wish my transform variable, so that adding the OR operator, and the words within the quotes are not to put the OR.

ALTER PROCEDURE
@Product = ' 'ORANGE LEMON' BANANA APPLE 'PEACH PEAR' '
AS

-- I WANT TRANSFORM THE WORDS
@PRODUCT = 'ORANGE LEMON' OR BANANA OR APPLE 'PEACH PEAR'
What I meant was that even using the full-text functionality. I'm using CONTAINS . But before the CONTAISN was :

SELECT Description FROM Production.ProductDescription WHERE CONTAINS ( Description, PRODUCT )

Since PRODUCT and was researched by words such as ORANGE LEMON OR OR OR BANANA APPLE OR PEAR OR PEACH .

What is wanted now the words that come from the WEB application within '' stay as if it were the AND operator then was :

Product = '' ORANGE LEMON ' BANANA APPLE ' PEACH PEAR ''

PRODUCT = ' ( ORANGE AND LEMON ) OR BANANA OR APPLE OR ( PEACH AND PEAR)
Go to Top of Page
   

- Advertisement -