在where子句之间使用select查询

Sha*_*kar 0 sql t-sql sql-server

我必须找出一个日期介于两个其他日期之间,这些日期是从Microsoft SQL Server中的不同表中选择的

即我想做点什么

     Select A.* from  ( select member.key, 
           case when effective_date between (select month_start and month_end 
           from sales_month 
           where month=2 and year=2013) bucket_1
           then 1 else 0 from member ) as A
          where a.bucket_1 != 0
Run Code Online (Sandbox Code Playgroud)

我必须复制不同月份的案例陈述.任何想法/帮助?

谢谢

尚卡尔.

Reg*_*ser 5

这可以通过JOIN来完成:

SELECT m.* 
FROM member m
JOIN sales_month sm
    ON sm.month = 2
    AND sm.year = 2013
    AND m.effective_date BETWEEN sm.month_start AND sm.month_end;
Run Code Online (Sandbox Code Playgroud)