Value should be 0 between the two dates?

后端 未结 2 1339
耶瑟儿~
耶瑟儿~ 2021-01-27 14:48

Using SQL Server 2000

I want to compare the table2.date between table1.from, table1.todate, if exist then value should be 0 (zero)

Table1

ID From         


        
2条回答
  •  走了就别回头了
    2021-01-27 15:28

    select t2.id, t2.date, coalesce(T.value, 0) value
    from table2 t2
    left join 
         (select t22.id, t22.date, t22.value
            from table2 t22
           where not exists (select null from table1 t1
                              where t22.date between t1.fromdate and t1.todate)
         ) T on t2.id = T.id and t2.date = T.date
    

提交回复
热议问题