## SEPARATE WTH HYPHEN TO STRING again

 Author Message anuj12paritosh Grasshopper Group: General Forum Members Points: 11 Visits: 162 HI ALLI HAVE STRING SUPPOSESTRING :-AD675498IJU76I WANT TO SEPARATE WITH HYPHEN (-)BUT EVERY TIME POSITION IS NOT FIX.ASSUME FIRST TIME POSITION IS :- 4THEN RESULT : -AD67-5498IJU76ASSUME NEXT TIME POSITION IS :- 4,6THEN RESULT : -AD67-54-98IJU76ASSUME NEXT TIME POSITION IS :- 4,7THEN RESULT : -AD67-549-8IJU76I WANT TO DYANAMIC QUERY FOR SOLVE THIS PROBLEMTHANKS IN ADVANCE. sqlsurfing SSC-Enthusiastic Group: General Forum Members Points: 167 Visits: 1130 How are you determining where the Hypens will be inserted? Do you have a spec/business rule? --------------------------------------------------...0.05 points per day since registration... slowly crawl up to 1 pt per day hopefully :-D anuj12paritosh Grasshopper Group: General Forum Members Points: 11 Visits: 162 hi i have to solve with above senario and above mention condition is exists world rVadim Ten Centuries Group: General Forum Members Points: 1054 Visits: 2299 If you know positions you can use STUFF function:`SELECT STUFF('AD675498IJU76', 5, 0, '-')SELECT STUFF(STUFF('AD675498IJU76', 5, 0, '-'), 8, 0, '-')SELECT STUFF(STUFF('AD675498IJU76', 5, 0, '-'), 9, 0, '-')` Lokesh Vij SSCommitted Group: General Forum Members Points: 1564 Visits: 1599 `DECLARE @hyphen VARCHAR(100) = '2,10', @inputstring VARCHAR(max) = 'ABCDEFGHIJKLMNOPQRST', @hyphen_count INT, @i INT=1, @key INT;SET @hyphen_count = LEN(@hyphen) - ( LEN(REPLACE(@hyphen, ',', '')) ) + 1WHILE @i <= @hyphen_count BEGIN IF ( CHARINDEX(',', @hyphen, 1) ) <> 0 SET @key = SUBSTRING(@hyphen, 1, CHARINDEX(',', @hyphen, 1) - 1) ELSE SET @key = @hyphen SET @inputstring = STUFF(@inputstring, @key + @i, 1, '-') SET @hyphen= SUBSTRING(@hyphen, @key + 1, LEN(@hyphen)) SET @i=@i + 1 ENDSELECT @inputstring ` ~ Lokesh Vij Guidelines for quicker answers on T-SQL questionGuidelines for answers on Performance questionsLink to my Blog Post --> www.SQLPathy.comFollow me @Twitter Lokesh Vij SSCommitted Group: General Forum Members Points: 1564 Visits: 1599 Create a function or stored procedure with @hyphen and @inputstring as arguments or parameters ~ Lokesh Vij Guidelines for quicker answers on T-SQL questionGuidelines for answers on Performance questionsLink to my Blog Post --> www.SQLPathy.comFollow me @Twitter