use tempdb
go
if object_id(
'CharsTable'
,
'U'
)
is
not
null
drop
table
CharsTable
create
CharsTable (letter
char
(1))
insert
into
select
'a'
'b'
'c'
'd'
'e'
'f'
declare
@string2
as
varchar
(1000)
--query 1
set
@string2 =
''
@string2 = @string2 + letter
from
--query 2
order
by
letter
desc
--query 3
@string2 = @string2 + ltrim(letter)
ltrim(letter)
CONVERT_IMPLICIT(varchar(1000),[@string2]+[tempdb].[dbo].[CharsTable].[letter],0)
ltrim([tempdb].[dbo].[CharsTable].[letter]) CONVERT_IMPLICIT(varchar(1000),[@string2]+ltrim([tempdb].[dbo].[CharsTable].[letter]),0)
".. we do not guarantee that @var = @var + will produce the concatenated value for any statement that affects multiple rows. The right-hand side of the expression can be evaluated either once or multiple times during query execution ..."
Congratulations on the guru award.
Great article.