This is a weird problem that is happening only on some SQL servers.

The following code
Code:
declare @ServerApps varchar(max)
declare @apps table(AppName varchar(100))

insert @apps(AppName) values('Application A')
insert @apps(AppName) values('Application B')
insert @apps(AppName) values('Application C')

select @ServerApps = ISNULL(@ServerApps, '') + '/' + AppName from @apps
--order by AppName

select @ServerApps
returns: "/Application A/Application B/Application C"

BUT, if I uncomment "order by AppName", then on some servers I get the same result, but other server I only get "/Application C"

First I thought it's the server version, but then I tried on 2 different SQL Server 2012, and on one I got the full strings concatenated, and the other one I only got "/Application C"

It only happens when there is an ORDER BY

Does anyone know what could be wrong? any settings in SQL Server that makes it behave like this?

Can you guys try it on your SQL Servers? what do you get?