Question: At <https://jsfiddle.net/mgjftrdz/1/>, instead of the following values:

```
var availableTags = [
     {label: 'honey', value: 1},
     {label: 'apples', value: 2},
     {label: 'milk', value: 3},
     {label: 'tea', value: 4},

```

I want to list AirportNames and AirportCodes like this:

```
 var availableTags = [
         {label: 'LAX - Los Angeles Airport', value: 'LAX'},
         {label: 'JFK - John F Kennedy Airport', value: 'JFK'},
         {label: 'LHR - London Heathrow Airport', value: 'LHR'},
         etc

```

I have a table of 8101 rows tblAirportNamesAndCodes.

Instead of doing a SqlDataReader loop in VB.NET like:

```
    Try
        sqlConnection1.Open()
        dr = cmd.ExecuteReader
        While dr.Read()
            strResult += "{label: '" + dr("AirportName") + "' value: '" + dr("AirportCode") +"'}," 

        End While

```

Is there a way in T-SQL to do all that concatenating at the SQL Server and have a stored procedure just return one long string? And would this be faster?

Answer: 
Yes. Do not optimize the wrong element.

So, no.

Seriously, if you have a problem transferring aound 8000 small rows then you either have an utterly crappy sql server (way less than my quite old phone) Or transfer them over a slow connection (internet). In both cases SQL is not your problem (in the 2nd place please put a web service in front of the SQL Server).

The one bad code I see is actually this:

> 
> strResult += "{label: '" + dr("AirportName") + "' value: '" + 
>  dr("AirportCode") 
> 
> 
> 

That is bad in 2 levels.

* It does dictionary lookups. Get the indices of the fields BEFORE the loop, then access by them ( i.e. 'dr(0)'). THat optimizes this.
* Do NOT put strings together like this. Put a StringBuilder there with appropriate size. You allocate a TON of strings just to throw them away.

Last time I did somersetting like that I Was reading half a million entries into a dictionary in half a second, so the SQL is NOT your problem. But your VB code is sloppy.

And if you pull that over a network connection from a VERY remote server - not a lot you can do without adding a web service.
You can use this query as start point:

```
declare @t as varchar(max)

select @t = coalesce(@t + ',
' + name, name) from syscolumns option (maxdop 1)

select @t

```

But I recommend you to retain formatting logic in your .NET code, instead of moving it to T-SQL. It is hardly to see the performance difference in your case, but your code will be more maintainable without formatting logic inside SQL.

UPD: Agree with @TomTom about StringBuilder.

P.S. Option (maxdop 1) in this sample only to keep order of rows for complex queries.