October 22, 2009 at 11:09 am
Is there a way to replace text in all tables for fields that are text datatype?
Thank you!
Norbert
October 22, 2009 at 11:14 am
Hi,
I used this to get rid of all £ signs out of data, you should be able to revise it for your purposes.
DECLARE @TableName VARCHAR(255)
SELECT @TableName = 'TableName'
DECLARE @sql VARCHAR(MAX)
SELECT @sql = 'UPDATE ' + QUOTENAME(@TableName) + '
SET
'
SELECT @sql = @sql + ColName + ' = REPLACE(' + ColName + ', ''£'', ''''),
'
FROM
(
SELECT syscolumns.name as ColName
FROM sysobjects
JOIN syscolumns ON sysobjects.id = syscolumns.id
JOIN systypes ON syscolumns.xtype = systypes.xtype
WHERE
sysobjects.name = @TableName
AND systypes.name = 'text'
) Cols
SELECT @sql = STUFF(@Sql, LEN(@Sql) - 3, 1, '')
PRINT (@Sql)
--uncomment following line when you are happy with output
--EXEC (@Sql)
///Edit commented out exec
October 22, 2009 at 11:18 am
How would I run it against all tables without specifying each one?
October 22, 2009 at 11:43 am
I found a solution here:
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy