声明放置temptable之间的SQL查询

时间:2015-01-23 11:12:04

标签: sql-server stored-procedures sql-server-2008-r2

我创建了名为temp_table的临时表,记录为

       FromDate                ToDate
2011-01-01 00:00:00.000  |  2012-08-16 17:26:44.827
2012-08-16 17:29:06.980  |  2115-01-23 16:29:46.443

我把声明放在

之间
select * 
from payment p 
inner join temp_table t 
    on t.FromDate >= p.CreatedDate 
    or t.toDate <= p.CreatedDate 
where createddate between temp_tbl.FromDate and temp_tbl.ToDate

但它依赖于1行语句,我希望两个语句都可以调用。

1 个答案:

答案 0 :(得分:0)

使用Between操作加入表On条件。试试这个。

select * 
from payment p 
inner join temp_table 
    on  p.CreatedDate between
        temp_tbl.FromDate and temp_tbl.ToDate