| Author |
Topic |
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 06:00:01
|
| Morning guys,Do you know how I would get this to work (with a set amount of characters to be showed to the left and right of each searched phrase? (I would need it so If someone wants to search 'flu', it returns the word flu, then the 8 characters to the left and right)declare @Phrase varchar(max)set @Phrase= char(32)+'this is a sample of what I want to find'select @Phrase=replace(@Phrase, ' '+8 Diagnosis +8' ',' ')from Consultationselect @PhraseGOThanks. H.[/fail at query] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-13 : 06:12:18
|
[code]select @Phrase, substring(@Phrase, charindex(@Word, @Phrase) - 8, len(@Word) + 16)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 06:18:43
|
| Cheers khtan. =)[/fail at query] |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 06:20:02
|
| What is @word? How do you declare it?[/fail at query] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-13 : 06:25:54
|
just declare it as a varchar variabledeclare @word varchar(100) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 06:34:49
|
| Cheers khtan. =)[/fail at query] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-13 : 07:10:24
|
| declare @Phrase varchar(1000),@word varchar(1900)set @Phrase= 'testing this is flu a sample of what I want to find'set @word='flu'select @Phrase as actual_word, @word as word_to_find,substring(@Phrase, charindex(@Word, @Phrase)-8,8) as left_eight,substring(@Phrase, charindex(@Word, @Phrase)+len(@word),8) as right_eightMadhivananFailing to plan is Planning to fail |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 07:26:40
|
| Thats what I like to see, a fully working reply. Madhivanan, Once again- Your the man!I would love to see inside your brain. :P[/fail at query] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-13 : 07:30:52
|
quote: Originally posted by winterhI would love to see inside your brain. :P[/fail at query]
are you Sylar ?  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 07:49:19
|
| maybe I am Sylar. OR Maybe I am Dancing Bojangles.[/fail at query] |
 |
|
|
|