Hi,
I assume you are referring to the order of the Value feature. You have to specify the Order by Clause in order to get the same order every time.
consider the below example
Create Table #TableName
(
Sno Int,
Company Nvarchar(40),
Location Nvarchar(100)
)
Insert into #TableName
Values(1,'A','California'),(2,'A','Florida'),(3,'A','Alabama')
Select (Select ',' + a.Location From #TableName a for Xml Path('') ,TYPE).value('.','VARCHAR(Max)') as CSV
Select (Select ',' + a.Location From #TableName a Order by ','+ a.Location for Xml Path('') ,TYPE).value('.','VARCHAR(Max)') as CSV
Drop Table #TableName
Go
The output for the first Query will be
CSV
,California,Florida,Alabama
The Output of the Second query will be
CSV
,Alabama,California,Florida