Find the ID number that does not exist in the data table

xiaoxiao2021-03-06  19

Create Procedure SP_Recycle

AS

Declare @Maxid Int, @ SQL VARCHAR (8000)

IF EXISTS (Select * from T)

Begin

SELECT @ maxid = max (id) from T

CREATE TABLE #T (ID INT)

Set @ SQL = 'SELECT TOP' CAST (@maxid as varchar) 'Identity (int, 1, 1) ID

INTO #Tem from syscolumns a, syscolumns b, syscolumns c

Insert #t

SELECT * FROM #TEM

Drop Table #tem '

EXEC (@SQL)

Select ID from #t where not exists (select * from t where id = # T.ID)

DROP TABLE #T

End

Go

转载请注明原文地址:https://www.9cbs.com/read-44603.html

New Post(0)