我在SQL Server中的查询遇到了奇怪的行为
我有两个表PrepaidTransactions
,BillingData
并且正在执行以下查询
Select *
from PrepaidTransactions
where customer_Id in
(Select customer_Id
from BillingData
where CommunityId = 10004)
该列customer_Id
不属于table BillingData
。查询没有执行错误,而是执行并返回PrepaidTransactions
表中的所有记录
但是当我运行以下查询时
Select customer_Id
from BillingData
where CommunityId = 10004
它显示一个错误
无效的列名“ customer_Id”。
谁能让我知道为什么第一个查询没有显示任何错误?
我认为这两篇文章回答了您的问题。
http://support.microsoft.com/kb/298674
这是预期的行为,因为您的列名未绑定到表。因此,如果可以在外部表中进行解析(在您的查询中可以),则子查询不会失败。如果指定表BillingData.customer_Id,则会失败。文章说遵循这种做法以避免模棱两可。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句