日期:2014-05-18 浏览次数:20595 次
--SQL2005 ;with ach as ( select rid=row_number() over (order by getdate()) from master..spt_values a,master..spt_values b where a.type = 'P' and b.type = 'P' ) select a.rid from ach a left join tb b on a.rid = b.id where b.id is null
------解决方案--------------------
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'A') BEGIN DROP TABLE A END GO CREATE TABLE A ( ID INT ) GO INSERT INTO A SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 5 UNION SELECT 6 UNION SELECT 8 GO SELECT number FROM A FULL OUTER JOIN (SELECT number FROM master..spt_values WHERE type = 'P' AND number > 0) AS B ON number = ID WHERE number <= (SELECT MAX(ID) FROM A) AND number >= (SELECT MIN(ID) FROM A) AND ID IS NULL number 4 7