I have a table with feilds like
TimeStamp | Feild1 | Feild 2
--------------------------------------
1902909002 | xyddtz | 233447
1902901003 | xytzff | 233442
1902901105 | xytzdd | 233443
1902909007 | xytzdd | 233443
1902909909 | xytsqz | 233436
Now i want to query it and fetch records like timestamp = 1902909002 approx OR 1902901003 approx OR ... I want i record for each epoch time which ever is nearest to that epoch
i have written something :
string sqlQuery = "SELECT TimeStamp, FwdHr, W FROM Meter_Data WHERE (TimeStamp <= "+timeSt[0].ToString();
for (int i = 1; i < timeSt.Count; i++)
{
sqlQuery = sqlQuery + " OR TimeStamp <= " +timeSt[i].ToString() ;
}
sqlQuery=sqlQuery+ ") AND MeterID = @meterID AND DeviceID = @deviceID ORDER BY TimeStamp";
which is returning null and also if from date and to date have large diff OR's will be in thousands. can any body suggest a better way?