SQLTeam.com | Weblogs | Forums

How to replace sub string by stuff?

I work on SQL server 2012 I face issue on #finaltable temp I have value field

SELECT DISTINCT
  [InputID],PART_ID,[Vendor ID],Manufacturer,[Digi-Key Part No.] ,[Mfr Part No.],[Description],Category,Family ,Obsolete ,[Non-Stock] 
  ,	[Part_Status],partNumber,CompanyName,DKFeatureName2,[Variant Number],IsUnit,
  SUBSTRING((
  
	 SELECT  isnull(StarFormat,'') + Value+ isnull(endFormat,'')
    FROM #FinalTable 
    WHERE ([InputID] = Results.[InputID] and DkFeatureId = Results.DkFeatureId) 

	FOR XML PATH(''),TYPE).value('.', 'NVARCHAR(MAX)')
	   
  ,1,5000) AS Value
FROM #FinalTable Results
where StatusId=3

How to replace sub string by stuff using stick | to separate value
and what is the meaning of expression above ?

  STUFF(SUBSTRING((
  
	 SELECT  '|' + isnull(StarFormat,'') + Value+ isnull(endFormat,'')
    FROM #FinalTable 
    WHERE ([InputID] = Results.[InputID] and DkFeatureId = Results.DkFeatureId) 

	FOR XML PATH(''),TYPE).value('.', 'NVARCHAR(MAX)')
	   
  ,1,5000),1,1,'') AS Value