Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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
 
Old August 5th, 2005, 10:56 AM
Authorized User
 
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old August 5th, 2005, 01:53 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Before you Insert the data, check the string for the domain name and use Replace() to replace it with a blank.

 
Old August 5th, 2005, 03:50 PM
Authorized User
 
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old August 5th, 2005, 11:55 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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.

 
Old August 6th, 2005, 06:25 AM
Authorized User
 
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old August 6th, 2005, 11:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

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
Code:
REPLACE
function in DataBase.

Always:),
Hovik Melkomian.
 
Old August 6th, 2005, 11:58 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   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]'




 
Old September 13th, 2005, 11:52 AM
Authorized User
 
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old September 13th, 2005, 12:28 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

My apolgies, my example deletes the rows. Use a trigger as melvik suggested and use a REPLACE to replace the string with blank ('').

 
Old September 13th, 2005, 12:54 PM
Authorized User
 
Join Date: Jun 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

Can I look for examples somewhere please as I don't know how to create a trigger.
I will really appreciate it.

Palvin






Similar Threads
Thread Thread Starter Forum Replies Last Post
Text Strings need help! julz127 Visual Basic 2005 Basics 2 January 26th, 2008 09:49 PM
Deleting text from a RichTextBox wslyhbb C# 0 October 29th, 2005 08:00 PM
Place text strings in a text box error_help Excel VBA 1 October 6th, 2005 05:26 AM
Automatically deleting from databases gmoney060 Classic ASP Basics 5 July 25th, 2004 12:02 PM
Automatically Finding and Deleting Blank rows Romulus Excel VBA 3 October 18th, 2003 09:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.