Author |
Topic |
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2011-10-03 : 11:39:28
|
Hi,I need to use like operator to search, five characters in middle than some value after 5 characters. Please see the output valueDeclare @tbl1 table (ID INT,Col1 varchar(50))INSERT INTO @tbl1SELECT 1,'Abc 12345 1999 mno'INSERT INTO @tbl1SELECT 2,'Abc 12 2001 xxx'INSERT INTO @tbl1SELECT 3,'Abc 12345 2002 ddxd'INSERT INTO @tbl1SELECT 4,'Mnop 12345 1999 ksks'INSERT INTO @tbl1SELECT 5,'Abc xyz 1999'Output looks like thisselect * from @tbl1 where col1 like '%Abc [five characters] 1999%'ID Col1 1 Abc 12345 1999 mno |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-03 : 12:00:57
|
select * from @tbl1 where col1 like '%Abc_____1999%'------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2011-10-03 : 12:06:26
|
how about the 5 words instate of letters? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-03 : 12:58:54
|
five words separated by space you mean?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2011-10-03 : 13:08:07
|
yes please. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-03 : 13:30:28
|
[code]SELECT t.ID,t.Col1FROM @Tbl tCROSS APPLY dbo.ParseValues(t.Col1,' ')fGROUP BY t.ID,t.Col1HAVING MAX(CASE WHEN f.ID=1 THEN f.Val ELSE NULL END) = 'Abc'AND MAX(CASE WHEN f.ID=6 THEN f.Val ELSE NULL END) = '1999'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2011-10-03 : 14:00:31
|
It took 22 minutes for 5 documents still not finish...i created parsevalues function as well...it does not work for 100k records. |
 |
|
Kristen
Test
22859 Posts |
Posted - 2011-10-03 : 14:05:53
|
If you want performance don't store your data like that, parse it into the constituent parts so that you have structured data and then query will be instance.You are trying to do the equivalent of using a phone directory to find people by the second line of their address ...If its a one-off query live with the fact that it takes 20 minutes. Otherwise improve the structure of the data. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-03 : 14:13:26
|
quote: Originally posted by rudba It took 22 minutes for 5 documents still not finish...i created parsevalues function as well...it does not work for 100k records.
why not try full text index then?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|