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
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No problem. I often reuse code and so I know all about the woes of copy and paste. :) Glad that was it.
ASKER