Monday, 20 January 2014

Replace First Occurrence of string in SQL Server


declare @str     varchar(1000),
  @searchString    varchar(100),
  @replaceString varchar(100)

select  @str   = ProductID in
 '(Select ChildProductid  from ProductBreakup where ProductID=111 )',
  @searchString    = 'ProductID ',
  @replaceString = 'l.ProductID'

select  @str,
 stuff(@str, charindex(@searchString    , @str), len(@searchString    ), @replaceString )

No comments:

Post a Comment