0

There are 2 user inputs, violation_type and vehicle. I want to pass these variables to back-end database to make a report in Matlab. I have tried with one variables and it works fine, but i do not know how to pass multiple variables to filter the database records according to user search.

vehicle = 'car';
violation _type = 'U turn';


'SELECT lic.licence_plate_num,lic.owner_name,lic.owner_address,lic.owner_tel_no,lic.owner_email,vio.violation_date,vio.violation_time,vio.vehicle_type,vio.violation_type FROM licence_plate_details lic RIGHT JOIN violated_vehicles vio ON lic.licence_plate_num = vio.licence_plate_num where vio.vehicle_type = ''', vehicle, ''''

1 Answer 1

1

Use AND keyword in your SQL query for multiple criteria. You can use SPRINTF MATLAB function to insert variable parameters. I've also separated your query into multiple substrings for better readability.

sql = sprintf( [ ...
    'SELECT lic.licence_plate_num, lic.owner_name, lic.owner_address, '...
    'lic.owner_tel_no, lic.owner_email, vio.violation_date, '...
    'vio.violation_time, vio.vehicle_type, vio.violation_type '...
    'FROM licence_plate_details lic RIGHT JOIN violated_vehicles vio '...
    'ON lic.licence_plate_num = vio.licence_plate_num '...
    'WHERE vio.vehicle_type = "%s" AND vio.violation_type = "%s"' ], ...
    vehicle, violation_type );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.