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.
| Author |
Topic |
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2011-12-01 : 11:08:33
|
How should i rewrite the below query to improve performancedelete from studentWHERE VALUE LIKE '%Open%'and VALUE NOT LIKE '%;%;%'delete from studentWHERE VALUE LIKE '%Close%'and VALUE NOT LIKE '%;%;%;%' |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-12-01 : 11:35:35
|
| If you really need leading wildcards, then you're not going to be able to optimize it. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-01 : 11:39:33
|
quote: Originally posted by sqlfresher2k7 How should i rewrite the below query to improve performancedelete from studentWHERE VALUE LIKE '%Open%'and VALUE NOT LIKE '%;%;%'delete from studentWHERE VALUE LIKE '%Close%'and VALUE NOT LIKE '%;%;%;%'
is value storing delimited item list?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-12-01 : 12:12:55
|
| you could combine themdelete from studentWHERE VALUE NOT LIKE '%;%;%;%'and (VALUE LIKE '%Close%' or VALUE LIKE '%Open%')That will do a single table scan but you won't be able to get away from a scan of some sort.You could put an index on VALUE so that it does an index scan maybe - might have to get the pk values (or unique clustered index values) and join to that for the delete.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2011-12-01 : 16:32:46
|
| Yes..the value storing delimited item list.. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-02 : 01:13:12
|
| what are you trying to find using above conditions? are you trying to check cases where Open/Close values are coming and having total og less than 3/4 items?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2011-12-02 : 10:45:16
|
| I am deleting the data with the condition specified.. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-02 : 10:47:07
|
quote: Originally posted by sqlfresher2k7 I am deleting the data with the condition specified..
i'm asking what are the conditions? didnt understand meanings of like '%;%;%' etc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|