临时表的一个用法

--AB:数据库

--Table1

 

SELECT * INTO #mytable1 FROM A.dbo.Table1 su WHERE su.code IN(SELECT su2.code FROM B.dbo.Table1 su2)

SELECT * from #mytable1

--DROP TABLE #mytable1

 

DECLARE myc CURSOR FOR SELECT * from #mytable1

OPEN myc

FETCH NEXT from myc

WHILE @@FETCH_STATUS=0

BEGIN

    INSERT INTO Table1

    (

        setid,

        code,

        dname,

        issys,

        menucodes,

        ddesc

    )

    SELECT setid,

        code,

        dname,

        issys,

        menucodes,

        ddesc

    FROM #mytable1

END

CLOSE myc

DEALLOCATE myc

你可能感兴趣的:(临时表)