can any one say what does this 0 and one 1 does here near the GPS_DATETIME and also whether the values get inserted
insert into @temp
SELECT REGISTRATIONNO,GPS_DATETIME,SPEED,
CASE WHEN BASESTATIONNAME IS NULL THEN LOCATION ELSE BASESTATIONNAME END AS LOCATION,
LAT_METER,LON_METER,ODOMETER
FROM GPSDATA_HISTORY
WHERE
GPS_DATETIME BETWEEN @v_from_date AND @v_to_date
and registrationno=@v_reg_no
union
select REGISTRATIONNO,GPS_DATETIME,SPEED,
LOCATION,
LAT_METER,LON_METER,ODOMETER from (SELECT TOP 1 REGISTRATIONNO,GPS_DATETIME,1 as speed,
CASE WHEN BASESTATIONNAME IS NULL THEN LOCATION ELSE BASESTATIONNAME END AS LOCATION,
LAT_METER,LON_METER,ODOMETER
FROM GPSDATA_HISTORY
WHERE GPS_DATETIME BETWEEN @v_from_date AND @v_to_date
and registrationno=@v_reg_no order by gps_Datetime desc)b
union
select REGISTRATIONNO,GPS_DATETIME,SPEED,
LOCATION,
LAT_METER,LON_METER,ODOMETER from (SELECT TOP 1 REGISTRATIONNO,GPS_DATETIME,0 as speed,
CASE WHEN BASESTATIONNAME IS NULL THEN LOCATION ELSE BASESTATIONNAME END AS LOCATION,
LAT_METER,LON_METER,ODOMETER
FROM GPSDATA_HISTORY
WHERE GPS_DATETIME BETWEEN @v_from_date AND @v_to_date
and registrationno=@v_reg_no order by gps_Datetime desc)c