Question: I build a sql query as:

```
declare @query1 varchar(1000)
declare @results varchar(4000)
set @results = ''

WHILE (condition)
BEGIN
   set @query1 = 'SELECT column FROM table'
   set @results = @results + ", " + (select @query1)
END

print @results

```

So, for example after 2 iterations, I would like to have:

```
columnvalue, columnvalue

```

However, in the above code, @results holds the actual sql query instead.

Answer: 
Ok, because I led you up the garden path with my previous answer, I ported [this](https://stackoverflow.com/a/27943/14357) to give you an algorithm that works:

```
void Main()
{
    double lat1=12.916933d, 
           lon1=77.562658d,
           lat2=12.930140d,
           lon2=77.587732d;
    double dist = GetDistanceFromLatLonInKm(lat1, lon1, lat2, lon2);
    // dist == 3.08890370651166 yay!

}

double GetDistanceFromLatLonInKm(double lat1,
                                 double lon1,
                                 double lat2,
                                 double lon2) {
  var R = 6371d; // Radius of the earth in km
  var dLat = Deg2Rad(lat2 - lat1);  // deg2rad below
  var dLon = Deg2Rad(lon2 - lon1); 
  var a = 
    Math.Sin(dLat / 2d) * Math.Sin(dLat / 2d) +
    Math.Cos(Deg2Rad(lat1)) * Math.Cos(Deg2Rad(lat2)) * 
    Math.Sin(dLon / 2d) * Math.Sin(dLon / 2d); 
  var c = 2d * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1d - a)); 
  var d = R * c; // Distance in km
  return d;
}

double Deg2Rad(double deg) {
  return deg * (Math.PI / 180d);
}

```

Your calculation appears to work correctly when you supply fixed values:

```
var lat1 = 0d;
var lon1 = 52d;
var lat2 = 0d;
var lon2 = -52d;

```

which rather implies that these conversions are failing:

```
double lat1 = Convert.ToDouble(TextBox1.Text);
double lon1 = Convert.ToDouble(TextBox2.Text);
double lat2 = Convert.ToDouble(TextBox3.Text);
double lon2 = Convert.ToDouble(TextBox4.Text);

```

If you're still having trouble, place a breakpoint on these lines and take a look at the values of `TextBox1.Text` etc.

For more predictable parsing of floating point numbers, it's best to supply culture information:

```
Convert.ToDouble("1.2", System.Globalization.CultureInfo.InvariantCulture)

```
Check if decimal delimiter is valid. It has to be comma or dot, depending on your regional settings.