Wednesday, 9 November 2011

Google API to get distance between two cities.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps JavaScript API Example: Extraction of Geocoding Data</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA7j_Q-rshuWkc8HyFI4V2HxQYPm-xtd00hTQOC0OXpAMO40FHAxT29dNBGfxqMPq5zwdeiDSHEPL89A" type="text/javascript"></script>
<!-- According to the Google Maps API Terms of Service you are required display a Google map when using the Google Maps API. see: http://code.google.com/apis/maps/terms.html -->
    <script type="text/javascript">

    var geocoder, location1, location2;
    function initialize() {
        geocoder = new GClientGeocoder();
    }

    function showLocation() {
        geocoder.getLocations(document.forms[0].address1.value, function (response) {
            if (!response || response.Status.code != 200)
            {
                alert("Sorry, we were unable to geocode the first address");
            }
            else
            {
                location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                geocoder.getLocations(document.forms[0].address2.value, function (response) {
                    if (!response || response.Status.code != 200)
                    {
                        alert("Sorry, we were unable to geocode the second address");
                    }
                    else
                    {
                        location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                        calculateDistance();
                    }
                });
            }
        });
    }

    function calculateDistance()
    {
        try
        {
            var glatlng1 = new GLatLng(location1.lat, location1.lon);
            var glatlng2 = new GLatLng(location2.lat, location2.lon);
            var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);
            var kmdistance = (miledistance * 1.609344).toFixed(1);

            document.getElementById('results').innerHTML = '<strong>Address 1: </strong>' + location1.address + '<br /><strong>Address 2: </strong>' + location2.address + '<br /><strong>Distance: </strong>' + miledistance + ' miles (or ' + kmdistance + ' kilometers)';
            //document.getElementById('results').innerHTML = '<strong>Distance: </strong>' + miledistance + ' miles (or ' + kmdistance + ' kilometers)';
        }
        catch (error)
        {
            alert(error);
        }
    }

    </script>
  </head>

  <body onload="initialize()">

    <form action="#" onsubmit="showLocation(); return false;">
      <p>
        <input type="text" name="address1" value="Address 1" class="address_input" size="40" />
        <input type="text" name="address2" value="Address 2" class="address_input" size="40" />
        <input type="submit" name="find" value="Search" />
      </p>
    </form>
    <p id="results"></p>

  </body>
</html>

Saturday, 5 November 2011

How to zoom In and zoom Out image in asp.net through javascript

ASPX Code : 
 <div>
    <img border="0" src="img1.jpg" width="100"height="100"
    onmouseover="zoom('247px','268px','296px','336px',this);"
    onmouseout="zoom('47px','68px','47px','68px',this);" />
    </div>
JavaScript Java :
   <script language="javascript" type="text/javascript" >
    var nW,nH,oH,oW;
    function zoom(iWideSmall,iHighSmall,iWideLarge,iHighLarge,whichImage)
    {   
        oW=whichImage.style.width;
        oH=whichImage.style.height;   
        if((oW==iWideLarge)||(oH==iHighLarge))   
        {
            nW=iWideSmall;
            nH=iHighSmall;
        }
        else
        {
            nW=iWideLarge;
            nH=iHighLarge;
        }
        whichImage.style.width=nW;
        whichImage.style.height=nH;
    }
  </script>

Tuesday, 4 October 2011

What is the difference between select count(*) and select count(any_column)?

  • COUNT(*) will include NULLS
  • COUNT(column_name) will not include NULLS.
Example :
create table myTable (id int,name nvarchar(100))
insert into myTable values(1,null)
insert into myTable values(null,'Hello')
insert into myTable values(null,null)

select COUNT(*) from myTable
Result : 3
select COUNT(name) from myTable
Result : 1

Sunday, 2 October 2011

Rename the Table/View/SP in SQL Server

sp_rename is used to rename the sql objects.
Syntax :
sp_rename 'Old Object Name','New Object Name'

sp_rename automatically renames the associated index whenever a PRIMARY KEY or UNIQUE constraint is renamed. If a renamed index is tied to a PRIMARY KEY constraint, the primary key is also automatically renamed by sp_rename.

Renaming a stored procedure, view or trigger will not change the name of the corresponding object name in the syscomments table. This may result in problems generating a script for the object as the old name will be inserted from the syscomments table into the CREATE statement. For best results, do not rename these object types. Instead, drop and re-create the object by its new name.
Note : sp_rename is not check  the object dependency.

Friday, 30 September 2011

Maximum Capacity Specifications for SQL Server

                        SQL Server (32/64-bit)
Nested stored procedure levels 32
Nested subqueries 32
Nested trigger levels 32
Nonclustered indexes per table 999
Parameters per stored procedure 2100
Parameters per user-defined function 2100
REFERENCES per table 253
User connections 32767
XML indexes 249
Rows per table Limited by available storage
Column in table 1024