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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 delete

Author  Topic 

suarezst1984
Starting Member

16 Posts

Posted - 2010-03-15 : 15:08:22
I have to two types of urls on a database one has the following format
www.google.com/p/partnumber

the other one

www.google.com/p/number_partnumber_character

i want to delete only the first time of url from the database
but i dont know how to write that delete statement so i dont delete the second type of url too

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-15 : 15:17:55
DELETE FROM YourTable WHERE YourColumn = 'www.google.com/p/partnumber'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

suarezst1984
Starting Member

16 Posts

Posted - 2010-03-15 : 15:19:33
the partnumber changes i forgot to mention that
Go to Top of Page

suarezst1984
Starting Member

16 Posts

Posted - 2010-03-15 : 15:20:21
and also the number and character from the second url
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-15 : 15:21:59
I don't understand what you mean. Please show us better sample data to help us understand your issue.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

suarezst1984
Starting Member

16 Posts

Posted - 2010-03-15 : 15:26:43
ok I have 2 types or urls in a database.
One of them has the following structure

www.mydomain.com/cellular/p/89898

and the other one

www.mydomain.com/cellular/p/bl_89898_23

(This are only examples since 89898 can be any number, and bl could be any combination of letters and 23 could also be any combination of two digits. But basically this is how my urls look. As you can see they are the same until you hit the /p/ after that they change. I want to be able to delete from the database the first type of urls
www.mydomain.com/cellular/p/89898 and keep the scond type
Go to Top of Page

suarezst1984
Starting Member

16 Posts

Posted - 2010-03-15 : 15:28:21
I tried stuff like delete from table_number where url like '%www.mydomain.com/cellular/p/%' and
url not like '%_%'

BUT it did not work
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-15 : 15:48:03
It's because underscore is a special character. You need to escape it with square brackets. See LIKE in BOL for more details.

NOT LIKE '%[_]%'

Also, remove the leading % here for better performance: WHERE url LIKE 'www...%'. You'll need it with the underscore part though.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-16 : 03:01:07
If the following gives the urls that should be deleted,

select url from your_table
where url like 'www.%/p/[0-9]%'


change it to delete

delete from your_table
where url like 'www.%/p/[0-9]%'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -