Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 SELECT REPLACE improvement required

Author  Topic 

j4ydh
Starting Member

18 Posts

Posted - 2013-05-13 : 06:04:41
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

52326 Posts

Posted - 2013-05-13 : 06:48:51
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

18 Posts

Posted - 2013-05-13 : 07:25:35
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

52326 Posts

Posted - 2013-05-13 : 07:34:35
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

18 Posts

Posted - 2013-05-13 : 07:46:56
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
   

- Advertisement -