Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,


i need the values of the other fields corresponding to distinct registrationno ,but the distict property should not be applied to the other fields

Here is my code:


SQL
select  'Active' as VS, registrationno, gps_datetime,speed,location  from gpsdata_previous   
where registrationno in(select registrationno from  vehicle_superuser where superuserid=@uid) AND(GPS_DATETIME BETWEEN @fromdate AND @todate)   
and   speed <>0 

union   
  
select 'Inactive' as VS,registrationno,gps_datetime,speed,location  from gpsdata_previous   
  
where registrationno in(select registrationno from  vehicle_superuser where superuserid=@uid)  AND(GPS_DATETIME BETWEEN @fromdate AND @todate)  
and  speed=0 



Please help me out.

Thanks.
Posted
Updated 10-Jan-12 23:45pm
v4
Comments
Slacker007 11-Jan-12 5:32am    
Edits made: formatting and some readability.
Amir Mahfoozi 11-Jan-12 6:24am    
Please make a small example with inputs and outputs to clarify your problem.

1 solution

Just remove all other fields from your select query and apply distinct on the registration_no.
 
Share this answer
 
Comments
ashok_89 11-Jan-12 5:44am    
i need the values of the other fields corresponding to distinct registrationno ,but the distict property should not be applied to the other fields

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