August 5, 2012 at 3:03 am
I am trying to use a variabe to camcattenate a string
I use following:
DECLARE @MYVAR Char(1000) = 'INITIAL'
if Conditon 1
SET @MYVAR = @MYVAR + ' ABC'
If Condition 2
SET @MYVAR = @MYVAR + 'DEF'
But Myvar nver changes from the Initial value
August 5, 2012 at 6:57 am
gerard-593414 (8/5/2012)
I am trying to use a variabe to camcattenate a stringI use following:
DECLARE @MYVAR Char(1000) = 'INITIAL'
if Conditon 1
SET @MYVAR = @MYVAR + ' ABC'
If Condition 2
SET @MYVAR = @MYVAR + 'DEF'
But Myvar nver changes from the Initial value
Nice trick!=)))
try
DECLARE @MYVAR varChar(1000) = 'INITIAL'
When you declare variable like char(n) and set it, the first M symbols will be set ('INITIAL'-7 chars in your case), other 1000-7=993 symbols will be ' '.
After that when you selecting variable in SSMS - it won't show you all the 1000 symbols, instead it will show you the several first one, and it will seem like 'INITIAL '.
August 5, 2012 at 7:59 am
Ok thanks for that.
So each time I Rtrim the variable and it seems to work
August 5, 2012 at 8:16 am
Yes, because it trims all the right spaces. So maybe you should consider to change data type to varchar.
Good luck!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply