Search code examples
jquerysqlsql-serverasp.net-coredapper

Join tables and filter by multiple condtions with Dapper in asp.net core mvc


I want to query join two tables with multiple conditions

  string sql = "Select l.*, c.FirstName_CompanyName from dbo.Loan l left join Customer c on  l.CustId=c.CustId where LoanAccountNo > 0 ";

When I implemented the above code, but I discovered I need to filter Loan table by Approved and Deleted But I can't seem to get it right.

The code below is what I have tried but didn't work

string sql = "Select l.*, c.FirstName_CompanyName from dbo.Loan WHERE Delete = 0 AND Approve = 1 l left join Customer c on  l.CustId=c.CustId where LoanAccountNo > 0 ";
{"Incorrect syntax near the keyword 'Delete'."}


Solution

  • Please use below code, there is a type error in the code, you added delete dna approve condition in between Loan table and alias l

    string sql = "Select l.*, c.FirstName_CompanyName from dbo.Loan l WHERE l.Delete = 0 AND l.Approve = 1 left join Customer c on  l.CustId=c.CustId where LoanAccountNo > 0 ";