Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Hi LeonNewbie,
- I wrote some code, explanations and examples for you. I also had to add some assumptions - maybe you have to alter the code if I got you wrong :-)
- */
- /* KeyWord 1 contains 2 phrases */
- --One has the keywords pingu and one has noot as seen below: This is stored in KEYWORD1
- DECLARE @KeyWord1_1 varchar(512)
- DECLARE @KeyWord1_2 varchar(512)
- SET @KeyWord1_1 = 'pingu'
- SET @KeyWord1_2 = 'noot'
- /* KeyWord 2 contains 2 phrases */
- --My other string has two keywords such as: Sponge and Bob...
- DECLARE @KeyWord2_1 varchar(512)
- DECLARE @KeyWord2_2 varchar(512)
- SET @KeyWord2_1 = 'sponge'
- SET @KeyWord2_2 = 'bob'
- /* Your input-variable */
- --Now when my staff use the program they have an option to enter some free text, they can enter anything e.g...
- DECLARE @teststring varchar(512)
- SET @teststring = 'sponge went noot or pingu goes bob.'
- -- EXAMPLES
- --SET @teststring = 'sponge bob'
- --SET @teststring = 'pingu noot'
- --SET @teststring = 'pingu bob'
- --SET @teststring = 'pingu bob'
- --SET @teststring = 'noot bob'
- DECLARE @done int
- SET @done = 0 -- we will need this for the further IFs :-)
- -- your requirement:
- -- If pingu noot exists then continue (= when the two phrases of keyword are given)
- --, otherwise if sponge bob exists continue (= when the two phrases of keyword are given)
- --or is pingu and bob exists continue
- --or if sponge and noot exists continue (also when pingu/sponge and noot/bob are given? (IF YES* IF NO**)
- -- **NO would mean: A full keyword, it can be mixed but it must fit a first and a second phrase
- -- *YES woudl mean: A whole keyword must be found, or a pharse from the first and the second keyword
- -- In my example I will stay with _NO_
- IF (@teststring LIKE '%'+@KeyWord1_1+'%' -- First Keyword - Full
- AND @teststring LIKE '%'+@KeyWord1_2+'%')
- AND @done = 0
- BEGIN
- PRINT 'If pingu noot exists then continue'
- SET @done = 1;
- END
- IF (@teststring LIKE '%'+@KeyWord2_1+'%' -- Second Keyword - Full
- AND @teststring LIKE '%'+@KeyWord2_2+'%')
- AND @done = 0
- BEGIN
- PRINT 'otherwise if sponge bob exists continue'
- SET @done = 1;
- END
- IF (@teststring LIKE '%'+@KeyWord1_1+'%' -- First Keyword, first Phrase and
- AND @teststring LIKE '%'+@KeyWord2_2+'%') -- Second Keyword, second Phrase
- AND @done = 0
- BEGIN
- PRINT 'pingu and bob exists continue'
- SET @done = 1;
- END
- IF (@teststring LIKE '%'+@KeyWord2_1+'%' -- Second Keyword, first Phrase and
- AND @teststring LIKE '%'+@KeyWord1_2+'%') -- First Keyword, second Phrase
- AND @done = 0
- BEGIN
- PRINT 'sponge and noot exists continue'
- SET @done = 1;
- END
- IF @done = 0
- BEGIN
- PRINT 'and i still haven''t found, what i''m looking for...'
- END
- -- If you also want to check the order (to prevent "noot pingu" from working) you can try this:
- SET @teststring = 'noot pingu' -- not working
- SET @teststring = 'pingu noot' -- it's okay
- SET @done = 0
- IF (@teststring LIKE '%'+@KeyWord1_1+'%' -- First Keyword - Full
- AND @teststring LIKE '%'+@KeyWord1_2+'%')
- AND @done = 0
- AND CHARINDEX(@KeyWord1_1,@teststring,1) < CHARINDEX(@KeyWord1_2,@teststring,1) -- that's the ticket...
- BEGIN
- PRINT 'If pingu noot exists - IN THE CORRECT ORDER then continue'
- SET @done = 1;
- END
- /*Also consider this is just how you could make it work - it is not meant to be a complete solution.
- It is no good way to ensure security and also check if your database is case sensitive!
- Regards
- tgr*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement