我知道这个查询有什么问题,因为看起来SQL已经从Product表中解除了我的转换日期(我需要3个字段,我需要组合起来制作日期)。我的问题是如何解决它?我无法轻易检查当前日期是否>超过三个单独的列,所以我需要将它们组合成一个日期。
select ProductID from ctbo.dbo.PRODUCT where (getdate() >
(Select
Convert(DATE,CAST([expYear] AS VARCHAR(10))+'-'+
CAST([expMonth] AS VARCHAR(10))+'-'+
CAST([expDay] AS VARCHAR(10)))
from PRODUCT where expYear not like '0' and expDay not like '0' and expMonth not like '0') )
答案 0 :(得分:3)
由于您的子查询返回多个值,您需要使用ANY关键字(以使条件应用于任何子查询结果)或ALL(适用于所有结果),例如:
select ProductID from ctbo.dbo.PRODUCT where (getdate() >
ANY(Select
Convert(DATE,CAST([expYear] AS VARCHAR(10))+'-'+
CAST([expMonth] AS VARCHAR(10))+'-'+
CAST([expDay] AS VARCHAR(10)))
from PRODUCT where expYear not like '0' and expDay not like '0' and expMonth not like '0') )