日期:2014-05-16 浏览次数:20924 次
SELECT TOP 1 NUMBER FROM MASTER..SPT_VALUES WHERE TYPE='P' AND NUMBER BWETEEN (SELECT MIN(ID) FROM TB) AND (SELECT MAX(ID) FROM TB) ORDER BY NUMBER ASC
------解决方案--------------------
查断号 N多
------解决方案--------------------
IF OBJECT_ID('TEST') IS NOT NULL DROP TABLE TEST GO CREATE TABLE TEST ( ID int, COL0 REAL, ) INSERT TEST VALUES(1,1) INSERT TEST VALUES(3,1) INSERT TEST VALUES(5,1) ;WITH T AS ( SELECT RN=ROW_NUMBER()OVER(ORDER BY GETDATE()),* FROM TEST ) SELECT TOP 1 a.RN FROM T A LEFT JOIN T B ON A.RN=B.ID WHERE B.ID IS NULL /* RN -------------------- 2 (1 行受影响) */
------解决方案--------------------
select top 1 一个字段+1 from 数据库中有三条记录 a where 一个字段+1 not in (select 一个字段 from 数据库中有三条记录) order by 1
------解决方案--------------------
也可以参考用VBA的方法,改编号为你的字段名
Public Function M_Find空编号(表名 As String, 起始号)
Dim rs As New ADODB.Recordset
ts = "select * from " & 表名 & " where 编号="
编号 = 起始号
msql = ts & 编号
rs.Open msql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do While Not rs.EOF
rs.Close
编号 = 编号 + 1
msql = ts & 编号
rs.Open msql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Loop
rs.Close
Set rs = Nothing
M_Find空编号 = 编号
End Function
------解决方案--------------------