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
 Other SQL Server 2008 Topics
 SELECT REPLACE improvement required
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

j4ydh
Starting Member

United Kingdom
18 Posts

Posted - 05/13/2013 :  06:04:41  Show Profile  Reply with Quote
Hello

I have a select replace statement that works like a dream apart from if the item isn't found:

REPLACE(REPLACE (Content,
'<xSomethingx>', @Something),
'<xSomethingElsex>', @SomethingElse)
AS ContentRep

So if <xSomethingElsex> isn't found within the field nvarchar(MAX) NULL is returned.

Any advice would be appreciated

Thank you in advance
J

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/13/2013 :  06:48:51  Show Profile  Reply with Quote
Thats not true. It wont return NULL if it cant find search string. NULL will be returned only if any of variables like @SomethingElse has NULL value

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

j4ydh
Starting Member

United Kingdom
18 Posts

Posted - 05/13/2013 :  07:25:35  Show Profile  Reply with Quote
Hi
The results returned are NULL / NOTHING in the results pane if the <xSomethingElsex> is not in the initial string.

Should I consider IF exists or am I completely of track.

Thanks
J
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/13/2013 :  07:34:35  Show Profile  Reply with Quote
can you show how your sample data is?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

j4ydh
Starting Member

United Kingdom
18 Posts

Posted - 05/13/2013 :  07:46:56  Show Profile  Reply with Quote
The data is HTML (table)

Snippet:

<tr><td colspan="3"><xSomethingx> <xSomethingElsex></td></tr>

nvarchar(MAX)

Replace works nicely as long as both <xSomethingx> and <xSomethingElsex> are in the string.

If the field only has <tr><td colspan="3"><xSomethingx></td></tr>

The results are "Nothing" because the parameter is also looking for <xSomethingElsex>

Regards
J
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.08 seconds. Powered By: Snitz Forums 2000