在 'AdmissionID' 附近预期条件的上下文中指定的非布尔类型的表达式
An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'
“/”应用程序中的服务器错误。
An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'.
描述:
在执行当前网络请求时出现未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:
System.Data.SqlClient.SqlException: An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'.
来源错误:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆栈跟踪:
[SqlException (0x80131904): An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1767866
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352418
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
System.Data.SqlClient.SqlDataReader.get_MetaData() +90
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1406
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +134
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +140
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +316
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1481
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +101
System.Web.UI.WebControls.ListControl.PerformSelect() +34
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.BaseDataBoundControl.set_RequiresDataBinding(Boolean value) +9844021
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewChanged(Object sender, EventArgs e) +15
System.Web.UI.DataSourceView.OnDataSourceViewChanged(EventArgs e) +105
System.Web.UI.WebControls.SqlDataSourceView.SelectParametersChangedEventHandler(Object o, EventArgs e) +31
System.Web.UI.WebControls.ParameterCollection.OnParametersChanged(EventArgs e) +20
System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +142
System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +101
System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +36
System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +257
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +589
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +101
System.Web.UI.WebControls.ListControl.PerformSelect() +34
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +23
System.Web.UI.Control.PreRenderRecursiveInternal() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
我的SQL命令是这样的>>SELECT * FROM [Bed] WHERE WardID = @WardID AND BedStatus = 'Available' AND BedNo NOT IN (SELECT BedNo FROM [AdmissionDetail], [Admission] WHERE ([AdmissionDate] <= @AdmissionDate AND [DischargeDate] >= @DischargeDate AND AdmissionStatus <> 'Discharged' AND [AdmissionDetail]AdmissionID = [Admission]AdmissionID))
我正在使用 Visual Studio 2013 并使用 asp:DropDownList 和 asp:SqlDataSource 来执行此操作。
我有 4 table,分别是 Admission、AdmissionDetail、Ward 和 Bed。
您在 where
子句
中 table alias
和 column name
之间缺少 点
..[AdmissionDetail].AdmissionID = [Admission].AdmissionID
另外记下几点。
始终使用正确的 INNER JOIN
连接两个 table 而不是旧式的逗号分隔连接并在 where
子句中单独保留 filters
而不是 Not In
子句 Not exists
这可能会提高性能,并且 NOT IN
将在 sub-query
returns 任何 NULL
值时失败
SELECT *
FROM [Bed] b
WHERE WardID = @WardID
AND BedStatus = 'Available'
AND NOT EXISTS (SELECT 1
FROM [AdmissionDetail]
INNER JOIN [Admission]
ON [AdmissionDetail].AdmissionID = [Admission].AdmissionID
WHERE b.bedno = BedNo
AND [AdmissionDate] <= @AdmissionDate
AND [DischargeDate] >= @DischargeDate
AND AdmissionStatus <> 'Discharged')
“/”应用程序中的服务器错误。
An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'.
描述:
在执行当前网络请求时出现未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:
System.Data.SqlClient.SqlException: An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'.
来源错误:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆栈跟踪:
[SqlException (0x80131904): An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1767866
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352418
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
System.Data.SqlClient.SqlDataReader.get_MetaData() +90
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1406
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +134
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +140
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +316
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1481
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +101
System.Web.UI.WebControls.ListControl.PerformSelect() +34
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.BaseDataBoundControl.set_RequiresDataBinding(Boolean value) +9844021
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewChanged(Object sender, EventArgs e) +15
System.Web.UI.DataSourceView.OnDataSourceViewChanged(EventArgs e) +105
System.Web.UI.WebControls.SqlDataSourceView.SelectParametersChangedEventHandler(Object o, EventArgs e) +31
System.Web.UI.WebControls.ParameterCollection.OnParametersChanged(EventArgs e) +20
System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +142
System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +101
System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +36
System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +257
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +589
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +101
System.Web.UI.WebControls.ListControl.PerformSelect() +34
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +23
System.Web.UI.Control.PreRenderRecursiveInternal() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
我的SQL命令是这样的>>SELECT * FROM [Bed] WHERE WardID = @WardID AND BedStatus = 'Available' AND BedNo NOT IN (SELECT BedNo FROM [AdmissionDetail], [Admission] WHERE ([AdmissionDate] <= @AdmissionDate AND [DischargeDate] >= @DischargeDate AND AdmissionStatus <> 'Discharged' AND [AdmissionDetail]AdmissionID = [Admission]AdmissionID))
我正在使用 Visual Studio 2013 并使用 asp:DropDownList 和 asp:SqlDataSource 来执行此操作。 我有 4 table,分别是 Admission、AdmissionDetail、Ward 和 Bed。
您在 where
子句
table alias
和 column name
之间缺少 点
..[AdmissionDetail].AdmissionID = [Admission].AdmissionID
另外记下几点。
始终使用正确的 INNER JOIN
连接两个 table 而不是旧式的逗号分隔连接并在 where
子句中单独保留 filters
而不是 Not In
子句 Not exists
这可能会提高性能,并且 NOT IN
将在 sub-query
returns 任何 NULL
值时失败
SELECT *
FROM [Bed] b
WHERE WardID = @WardID
AND BedStatus = 'Available'
AND NOT EXISTS (SELECT 1
FROM [AdmissionDetail]
INNER JOIN [Admission]
ON [AdmissionDetail].AdmissionID = [Admission].AdmissionID
WHERE b.bedno = BedNo
AND [AdmissionDate] <= @AdmissionDate
AND [DischargeDate] >= @DischargeDate
AND AdmissionStatus <> 'Discharged')