SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 simple replace
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 04/29/2013 :  12:30:43  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
Hi All,

I got a table that has tons of <br>
What statement do i need to use to replace them with Line breaks ?

thanks a lot

James K
Flowing Fount of Yak Knowledge

3707 Posts

Posted - 04/29/2013 :  12:49:05  Show Profile  Reply with Quote
UPDATE Tbl SET YourColumnName = REPLACE(YourColumnName,'<br>',CHAR(13)+CHAR(10));
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 04/29/2013 :  12:49:20  Show Profile  Reply with Quote
Check if this works for you ..

Replace (ColumnName,'<br>',char(13))

Cheers
MIK
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3707 Posts

Posted - 04/29/2013 :  17:24:25  Show Profile  Reply with Quote
To add to what MIK and I posted: Depending on the OS for which you are targeting the resultant data, you would want to replace with a LF (char(10)), a CR only (char(13)) or both as CR+LF or LF+CR. Windows uses CR+LF. http://en.wikipedia.org/wiki/Newline
Go to Top of Page

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 04/30/2013 :  12:30:52  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
aaah forgot to saw it is a TEXT field.
This doesn't work.
How should i do it?
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/30/2013 :  12:34:10  Show Profile  Reply with Quote
I haven't tried this, but maybe try casting the TEXT to (N)VARCAHR(MAX), do the repalcement and then cast it back to TEXT?
Go to Top of Page

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 04/30/2013 :  13:08:48  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
Hi Lamprey,

can you send me the sql please i'm clueless

thanks a lot
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3707 Posts

Posted - 04/30/2013 :  13:54:51  Show Profile  Reply with Quote
UPDATE Tbl SET YourColumnName = REPLACE(CAST(YourColumnName AS VARCHAR(MAX)),'<br>',CHAR(13)+CHAR(10));
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/30/2013 :  14:42:33  Show Profile  Reply with Quote
quote:
Originally posted by James K

UPDATE Tbl SET YourColumnName = REPLACE(CAST(YourColumnName AS VARCHAR(MAX)),'<br>',CHAR(13)+CHAR(10));


Again, I haven't tried, but you might need to cast it back to TEXT before the update:

UPDATE Tbl SET YourColumnName = CAST(REPLACE(CAST(YourColumnName AS VARCHAR(MAX)),'<br>',CHAR(13)+CHAR(10)) AS TEXT);
Go to Top of Page

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 04/30/2013 :  15:36:44  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
Thanks a lot that did the trick!
So now you know it works :-)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000