Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
can any one say what does this 0 and one 1 does here near the GPS_DATETIME and also whether the values get inserted



SQL
 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
Posted
Updated 3-Nov-11 19:43pm
v4

Zero would be the data in third column which is named speed.

May be they are going to do some more action on the speed field and it should start from zero :-?

If you see further operations on this SQL you may find out why they need a zero as the initial value for speed.

Edit : after you provided more SQL statements :

It is because they UNIONed 3 tables and they need to have equal number of fields and datatypes.

But something that is very strange is that the second and third query return only on record with the same data and it is the last happened event in GPS_DATETIME table which happened between @v_from_date AND @v_to_date
But the second table has the zero speed and the third SQL result have the speed of 1.

So you have always this in output
R1
R2
.
.
.
RN
RN(speed=0)
RN(speed=1)
*if the output of the first SQL was sorted by GPS_DATETIME

So it seems that you need to track the SQL result and see where its used and how they used the last two records :-?

Hope this helps.
 
Share this answer
 
v2
Comments
ashok_89 4-Nov-11 5:33am    
ya what u told is correct thanks a lot
Amir Mahfoozi 4-Nov-11 5:51am    
You're welcome ;)
RaisKazi 5-Nov-11 11:31am    
My 5!
Amir Mahfoozi 5-Nov-11 14:12pm    
Thank you :)
Select statements usually get their data from columns and you can change the column name to something more readable by using the as key word, sometimes your column values are computed and not directly from the table itself.

This is the case with the 0, and it means show a column in the output and put the value zero in it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900