August 23, 2014 at 11:20 am
I have a Function where I want to put a character in a particular position in a Destination string. For example, I have a 5 character field containing, say, "12345". I would like to put the letter "A" in the third position resulting in "12A45". I'm trying the following
DECLARE @RetVal as varchar(5)
SET SUBSTRING(@RetVal,3,1) = 'A'
I'm getting a compiler error
"incorrect syntax near '@RetVal'. Expecting '(' or SELECT"
Am I using the wrong Function to do this? If so, what should I be using?
Thanks, Eddie
August 23, 2014 at 11:38 am
You can STUFF it!
DECLARE @Val1 varchar(5) = '12345'
declare @RetVal varchar(10)
set @RetVal = STUFF(@Val1,3,1,'A')
select @Val1
, @RetVal
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 23, 2014 at 3:06 pm
That worked... thanks, Eddie
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply