AbeSpain
asked on
String concatenation inside a loop is not returning what I expect
I have the following function that simply returns a number of hyphens equal to the argument length passed in to the function. However, it only returns one hyphen.
Alter Function CreateWhiteSpace (@WhiteSpaceCount Int)
Returns char(32)
As
Begin
Declare @I Int
Declare @WhiteSpace Char(32)
Set @I = 0
While @I <= @WhiteSpaceCount
Begin
Set @WhiteSpace = COALESCE(@WhiteSpace,'-') + '-'
Set @I = @I + 1
End
return @WhiteSpace
End
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
No problem. I often reuse code and so I know all about the woes of copy and paste. :) Glad that was it.
ASKER