 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 5th, 2005, 10:56 AM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Deleting text strings automatically from Database
Hello,
How can I automatically remove a particular text string from my database columns? Here is what I want to do...
I have a database on SQL 2000 server which stores the information about users. I want that when a user enters their profile information, If somebody enters any particular words like "domain.com" or any other string, it is automatically deleted from that column without the user being notified, so that if somebody views that profile those words are deleted from their profile.
Thanks in advance,
Palwinder
|
|

August 5th, 2005, 01:53 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Before you Insert the data, check the string for the domain name and use Replace() to replace it with a blank.
|
|

August 5th, 2005, 03:50 PM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply Jbenson. Is there any examples or illustration to this process as I am not a master of SQL. I just started SQL 3 weeks ago.
Thanks
|
|

August 5th, 2005, 11:55 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Do you have a list of specific strings that you don't want inserted? If so, you can create a table and enter them, then join the 2 tables, and delete if there is a match. I will explain more. First let me know if you have a list of strings that you want to exclude.
|
|

August 6th, 2005, 06:25 AM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by jbenson001
Do you have a list of specific strings that you don't want inserted? If so, you can create a table and enter them, then join the 2 tables, and delete if there is a match. I will explain more. First let me know if you have a list of strings that you want to exclude.
|
I don't want anybody to write "Yahoo, hotmail, mail, @, .com" I think if you can help me in this then later on I can modify the code to add or remove other strings.
Thanks
|
|

August 6th, 2005, 11:56 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Dear Palvin:
As jbenson001 mentioned its better to have atable included unwanted texts & join it with ur inserting data. u can also use it in trigger
but if ur words r really less than 10 & its fix & wont be more u can use
function in DataBase.
Always:),
Hovik Melkomian.
|
|

August 6th, 2005, 11:58 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Create a table with a column that contains strings you want to exclude: Say the table has a column named ExcludeString defined as varchar(30) for example.
Let the user enter whatever they want, and insert it into your profile table. (Let's say that column is named EMail)
After the insert into your profile table, delete if they have entered a string you want to exclude:
Delete From Profile --assuming this is the name of your main table, change as needed.
From profiles p
Inner Join exclusions e ON --exclusions is the table of strings you want to exclude ... change as needed
CHARINDEX(e.excludestring, p.email) > 0
*** Note that entering a string like 'mail' will remove any email with 'mail' in the string which will also remove is for example an email = ' [email protected]'
|
|

September 13th, 2005, 11:52 AM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Jbenson001,
I am sorry I was away for one month. So was not able to reply. I tried your suggestion. It is working, but it just deletes the whole user account. If user comes back to logon, it says account does not exists.
Here is how I am using it
Delete From UserInfo
From UserInfo p
Inner Join Exclusion e ON --exclusions is the table of strings you want to exclude ... change as needed
CHARINDEX(e.exclusions, p.AboutYourself) > 0
Now the UserInfo table includes all the fields about user's profile including username n password. So I guess right now it is deleting the whole row.
Please suggest.
Thanks,
Palvin
|
|

September 13th, 2005, 12:28 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
My apolgies, my example deletes the rows. Use a trigger as melvik suggested and use a REPLACE to replace the string with blank ('').
|
|

September 13th, 2005, 12:54 PM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
Can I look for examples somewhere please as I don't know how to create a trigger.
I will really appreciate it.
Palvin
|
|
 |