INSERT INTO ZZG.dbo.tab_TEST1(AA,BB,CC)
SELECT DD,EE,RQ from tab_TEST2
where tab_xmzhxx.RQ > (getdate() - 7) and tab_TEST2.DD not in (select GG from tab_TEST3) and tab_TEST2.DD not in (select HH from tab_TEST4)
我是想把,TEST2中的RQ(日期)在7天以内,DD(是个编号——无重复)中的编号未在TEST3中的GG和TEST4中的HH里出现过的数据插入到TEST1中,请问这样写对吗?
---------------------------------------------------------------
INSERT INTO ZZG.dbo.tab_TEST1(AA,BB,CC)
SELECT DD,EE,RQ from tab_TEST2
where tab_xmzhxx.RQ > (getdate() - 7)
and not exists(select gg from tab_test3 where tab_TEST2.DD = tab_test3.GG)
and not exists(select gg from tab_test4 where tab_TEST2.DD = tab_test4.hh)
---------------------------------------------------------------
INSERT INTO ZZG.dbo.tab_TEST1(AA,BB,CC)
SELECT DD,EE,RQ from tab_TEST2
where tab_TEST2.RQ <= (getdate() - 7)
and not exists(select gg from tab_test3 where tab_TEST2.DD = tab_test3.GG)
and not exists(select gg from tab_test4 where tab_TEST2.DD = tab_test4.hh)
---------------------------------------------------------------
楼主是对的吧!但时间:
INSERT INTO ZZG.dbo.tab_TEST1(AA,BB,CC)
SELECT DD,EE,RQ from tab_TEST2
where tab_xmzhxx.RQ>=(dateadd(day,-7,getdate()) and tab_TEST2.DD not in (select GG from tab_TEST3) and tab_TEST2.DD not in (select HH from tab_TEST4)