0

I am trying to create a stored procedure that replaces all values in one column with Xs the same length as the original values. Here is what I have so far:

SELECT REPLICATE('x', LEN(Name))

This code shows the output with Xs but it does not make this change permanently in the database. Is there a way to make this change permanently in the database?

Cat4Storm
  • 3
  • 1
  • 3
  • 2
    Yes, you need to use an `UPDATE` statement. But, why do you want to permanently make this change? This will effectively be erasing all data for that column. – Siyual Jul 18 '16 at 17:54
  • Thanks for your reply. How would I implement this in an update statement? – Cat4Storm Jul 18 '16 at 17:57

1 Answers1

2

You need to use an UPDATE statement to physically modify the record:

Update  YourTable
Set     Name = Replicate('x', Len(Name))

However, I would caution that this will update EVERY record in your table to just XXXX.... You will be effectively removing/destroying all data in that column.

Please do not run this statement unless you are absolutely certain this is what you intend to do.

If your goal actually is to remove all data from that column for every record, and your field is nullable, you could save some space by doing:

Update   YourTable
Set      Name = Null
Siyual
  • 16,415
  • 8
  • 44
  • 58