简体   繁体   English

sql server检查是否大于select语句

[英]sql server check for greater than with select statement

Why can't I do something like this: 我为什么不能做这样的事情:

    select distinct ps.ID, from vwList wt
    where Flag = 1 
    and GETDATE()  < (select dbo.fn_Date(ps.date1,ps.UploadDate) from pseres ps where ps.ID = wt.ID)  

I get The multi-part identifier "ps.ID" could not be bound. 我得到不能绑定多部分标识符“ ps.ID”。

Since ps.ID matches wt.ID, and ps is only mentioned in a subquery, why not: 由于ps.ID与wt.ID匹配,并且ps仅在子查询中提及,为什么不这样做:

select distinct wt.ID from vwList wt

?

The problem is in the outer select. 问题出在外部选择。 Try this: 尝试这个:

select distinct wt.ID
from vwList wt
where Flag = 1 and
      GETDATE()  < (select dbo.fn_Date(ps.date1,ps.UploadDate) from pseres ps where ps.ID = wt.ID)   

PS is in an inner select in the where clause. PS在where子句的内部选择中。 If you want to select the column from pseres then you need to have it in the from clause or as a join. 如果要从pseres中选择列,则需要将其包含在from子句中或作为联接。

This should work: 这应该工作:

SELECT DISTINCT wt.ID
FROM vwList wt
    INNER JOIN (SELECT dbo.fn_Date(ps.date1,ps.UploadDate) AS MyDate FROM pseres) ps ON     wt.ID = ps.ID
WHERE Flag = 1 AND
      MyDate > GETDATE()  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM