0

我知道这个查询有什么问题,因为似乎 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') )
4

1 回答 1

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') ) 
于 2013-08-19T21:58:52.740 回答