Updating a column using %

Hi,

I have a table called MyTable.
I want to update comments value for the rows that ends with '[address]' and '[phone]' from the paths specified in 'directory' column.
MyTable looks like this.

ID| directory                    |Comments
1 | A\B\C\D\[address]      |Jason
2 | E\F\G\K\[[bank]         |Poland
3 | H\I\J\L\[phone]          |Tree
4 | AA\CA\BB\D\[county]  |Oregon is near!
5 | KI\Y\Z\NC\[salary]      |
.
.
.

I used the query like

Use master
Update MyDB.dbo.MyTable set comments = 'MyFolder'
Where directory like '%address]' or
directory like '%phone]'

This actually works fine.  However, is there any part that I need to modify my script so that it becomes more efficient/elegant code?
IzzyTwinklyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sammySeltzerCommented:
I would have done it the same way quite frankly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bhavesh ShahLead AnalysistCommented:
Hi,

if [address]is coming always @ last place then you can use

Where directory like '%address]' or  directory like '%phone]'

Open in new window



second way is

Where charindex('address',directory) > 0

Open in new window




-bhavesh
mcs0506Commented:
HI,
I think this query is already written in efficient way as you done

Use master
Update MyDB.dbo.MyTable set comments = 'MyFolder'
Where directory like '%address]' or
directory like '%phone]'


But don't  forget to change your database from Master to your Database name when you executing script.

Regards,

Dani
LowfatspreadCommented:
using a separate column to store the "immediate" directory name separate from the rest of the path

would allow for a more efficient processing option for the query (assuming you then index the new column) as you
wouldn't need the wildcard and an index lookup could be performed rather than the full table scans required at present...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.