Server Error in '/' Application.

Incorrect syntax near the keyword 'AS'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Incorrect syntax near the keyword 'AS'.

Source Error:


Line 24: sql = "SELECT        MR_Barns.State, derivedtbl_1.FS700A, mr_barns.id FROM            MR_Barns with(nolock) INNER JOIN                             (SELECT        id, BarnID, FS700A                               FROM            MR_Reports with(nolock)                               WHERE        (id IN                                                             (SELECT        MAX(id) AS Expr1                                                               FROM            MR_Reports with(nolock) AS MR_Reports_1 GROUP BY BarnID))) AS derivedtbl_1 ON MR_Barns.id = derivedtbl_1.BarnID WHERE        (MR_Barns.Weekly = 1) and fs700a is not null order by state"
Line 25: dim rsStates as object = Server.CreateObject("ADODB.Recordset")
Line 26: rsStates.Open(sql, conn, 0, 1)
Line 27: %>
Line 28: 

Source File: E:\Cattle\markets\index.aspx    Line: 26

Stack Trace:


[COMException (0x80040e14): Incorrect syntax near the keyword 'AS'.]
   Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) +1483
   Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn) +281
   ASP.markets_index_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in E:\Cattle\markets\index.aspx:26
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +117
   System.Web.UI.Page.Render(HtmlTextWriter writer) +39
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +79
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8753


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.4087.0