I cant locate the SQL statement syntax error and I also dont know how and where to put the entry parameters
Im a beginner in SQL and currently in an internship to finish my studies. I’m working on a report page. I’ve attached two screenshots of the page so you can understand.
report page & result after generate report
First problem, I cant find the syntax error in the statement. The error said System.Data.SqlClient.SqlException: ‘Incorrect syntax near ‘=’.’
This is my SQL statement in my controller.
public ActionResult ReportIssue()
{
if (Session["User_Name"] == null)
return RedirectToAction("Login", "Account");
else
{
ViewBag.ValidationErrorMsg = "";
string get_report_issue = "select i.ISSUE_NUM,i.PRIORITY, i.MODULE,CONCAT(i.TITLE, CHAR(13),CHAR(10), i.DESCRIPTION) AS DESCRIPTION, CONVERT(varchar, i.CREATED_DATE, 103)AS Reported_Date,CONCAT(i.ISSUE_TYPE, CHAR(13), CHAR(10), i.ISSUE_CATEGORY,CHAR(13), CHAR(10), i.ISSUE_RESOLUTION) as Issue_Resolution," +
"CONVERT(varchar, (select min(MODIFIED_DATE)from NEPS.dbo.WEBGIS_ISSUE_LOG where i.issue_num = issue_num and FIELD = 'STATUS' and OLD_VALUE = 'NEW'),103) as RESPOND_DATE,STUFF((SELECT ',' + a.NEW_VALUE FROM NEPS.dbo.WEBGIS_ISSUE_LOG WHERE a.ISSUE_NUM = i.ISSUE_NUM ORDER BY a.NEW_VALUE FOR XML PATH('')), 1, LEN(','), CHAR(13)) AS ACTION_TAKEN, ISNULL((select max(MODIFIED_DATE)from NEPS.dbo.WEBGIS_ISSUE_LOG where i.issue_num = issue_num and FIELD = 'STATUS' and NEW_VALUE = 'RESOLVED' )," +
"(select max(MODIFIED_DATE) from NEPS.dbo.WEBGIS_ISSUE_LOG where i.issue_num = issue_num and FIELD = 'STATUS'and NEW_VALUE = 'CLOSED')) AS RESOLVED_DATE, i.STATUS FROM NEPS.dbo.WEBGIS_ISSUE iLEFT JOIN NEPS.dbo.WEBGIS_ISSUE_LOG C ON i.ISSUE_NUM = C.ISSUE_NUMwhere(C.FIELD = 'REMARKS' or C.FIELD = 'STATUS')AND(C.MODIFIED_DATE between { SESSION.CREATED_DATE}and { SESSION.MODIFIED_DATE} ) AND(i.APPLICATION ={ SESSION.APPLICATION}OR 'ALL' = { SESSION.APPLICATION}) AND(i.ENVIRONMENT ={ SESSION.ENVIRONMENT}OR 'ALL' = { SESSION.ENVIRONMENT})group by i.ISSUE_NUM,i.PRIORITY, i.MODULE,i.TITLE,i.DESCRIPTION,i.CREATED_DATE,i.ISSUE_TYPE,i.ISSUE_CATEGORY,i.ISSUE_RESOLUTION,i.STATUS]";
var reportIssue = db.Database.SqlQuery<ReportIssue>(get_report_issue).ToList();
ViewBag.ReportIssue = reportIssue;
SetUserViewBag();
return View();
}
}
One more thing, I also need help with entry parameters. Where and how should I put it?
{SESSION.CREATED_DATE}
{SESSION.MODIFIED_DATE}
{SESSION.APPLICATION}
{SESSION.ENVIRONMENT}
This is my model, just in case
public class ReportIssue
{
public string ISSUE_NUM { get; set; }
public string PRIORITY { get; set; }
public string MODULE { get; set; }
public string PROBLEM_DESCRIPTION { get; set; }
public string REPORTED_DATE { get; set; }
public string RESPOND_DATE { get; set; }
public string ISSUE_RESOLUTION { get; set; }
public string ACTION_TAKEN { get; set; }
public string RESOLVED_DATE { get; set; }
public string STATUS { get; set; }
}