Guest User

Guest User

  • Tech Writer
  • 58
  • 4.8k

select top six car by fueltype

Mar 10 2022 9:58 AM

Hello 

I want data according to of top-six car by fuel type and using this query

public static string TopSixCarsByFuel(string _fuel)
{
    var _sql = "SELECT TOP(6)ci.car_ID,ci.user_ID,ci.brand,ci.modelType,ci.expectedPrice,ci.transmission,ci.saleCity,ci.modelYear,ci.totalDriven,ci.modelYear,ci.fuelType,ci.color,cd.primaryImage AS primary_Image,cd.imagePath as image_Path FROM CarInfo ci ";
    if (!string.IsNullOrEmpty(_fuel) && _fuel != "")
    {
        _sql += "INNER JOIN CarDetail cd ON ci.car_ID=cd.car_ID WHERE ci.fuelType='" + _fuel + "' AND cd.primaryImage=1 AND adContentType='Good'  AND (ci.isSold<>1 or ci.isSold is null);";

    }
    else
    {
        _sql += "INNER JOIN CarDetail cd ON ci.car_ID=cd.car_ID WHERE cd.primaryImage=1 AND adContentType='Good'  AND (ci.isSold<>1 or ci.isSold is null);";

    }
    return _sql;
}
C#

but didn't get it


Answers (4)

1
Guest User

Guest User

  • Tech Writer
  • 58
  • 4.8k
Mar 11 2022 4:42 AM

Attachment: source.zip

Muhammad Imran Ansari
 
 
my senerio is i want a data according to fuel type and on the click of different tab  like (Petrol,CNG,) get data of it
1
Muhammad Imran Ansari

Muhammad Imran Ansari

  • 292
  • 6.3k
  • 298.8k
Mar 10 2022 1:04 PM
Garima, Are you getting any error or empty result?
Can you share you table schema with some data? 
1
Guest User

Guest User

  • Tech Writer
  • 58
  • 4.8k
Mar 10 2022 11:59 AM
Muhammad Imran Ansari
 
 
doesn't work for me 
1
Muhammad Imran Ansari

Muhammad Imran Ansari

  • 292
  • 6.3k
  • 298.8k
Mar 10 2022 10:33 AM
Try the following query:
  1. public static string TopSixCarsByFuel(string _fuel)  
  2.         {  
  3.             var _sql = " SELECT TOP(6) ci.car_ID,ci.user_ID,ci.brand,ci.modelType,ci.expectedPrice,ci.transmission,ci.saleCity,ci.modelYear,ci.totalDriven,ci.modelYear,ci.fuelType,ci.color,cd.primaryImage AS primary_Image,cd.imagePath as image_Path FROM CarInfo ci ";  
  4.             _sql += " INNER JOIN CarDetail cd ON ci.car_ID=cd.car_ID WHERE cd.primaryImage=1 AND adContentType='Good'  AND (ci.isSold<>1 or ci.isSold is null) ";  
  5.   
  6.             if (!string.IsNullOrEmpty(_fuel))  
  7.                 _sql += " AND ci.fuelType='" + _fuel + "' ";  
  8.                   
  9.             return _sql;  
  10.         }