我想在插入查询中添加此代码.............
DECLARE @Upper INT;
DECLARE @Lower INT;
SET @Lower = 1
SET @Upper = 613
DECLARE @R INT = (SELECT @Lower + CONVERT(INT, (@Upper-@Lower+1)*RAND()))
;WITH MyTable AS (
SELECT (ROW_NUMBER()OVER (ORDER BY MyTable.SomeFiled)) as row,*
FROM MyTable)
SELECT * FROM rat.MLTFQuestion WHERE MyTable= @R
答案 0 :(得分:0)
CTE table只是一个临时表,因此您可以这样使用它:
;WITH MyTable AS (
SELECT (ROW_NUMBER()OVER (ORDER BY MyTable.SomeFiled)) as row,*
FROM MyTable)
insert into newtable(row, col2, col3)
SELECT row,col2,col3 FROM MyTable