I'm a little green when it comes to SQL Server string manipulation functions. If I have a string with six characters in it, say:
DECLARE @p_MyStringVariable VARCHAR (100)
SET @p_MyStringVariable = 'FANFFF'
And I want to insert, say, the letter 'M' in the first and seventh positions of the final string and assign that to another VARCHAR variable to read 'MFANFFMF', how can I best do that? And am I correct in reading that SQL Server strings are indexed starting from one, instead of zero? I'm thinking of the SUBSTRING() function, for instance.
(Note that some strings will be up to开发者_JS百科 100 characters in length, thus the VARCHAR(100) declaration above, even for a six-character string)
Thanks much for your help.
You could also take a look at the STUFF function.
SELECT STUFF(STUFF(@p_MyStringVariable,1,0,'M'),7,0,'M')
Yes, SQL Server indexes varchar etc columns starting at one.
To insert at specfic points, use STUFF (and see Joes's answer for examples)
精彩评论