如何删除表格的第一行,然后将同一行(包含更新的信息)添加到表格底部?
换句话说,
如何在查询中在表格底部插入行?
代码摘要:
循环(不包括在内)
现在,这应该重复每一行。但有时查询决定将更新的行插回到查询的顶部,以便它不断更新并一遍又一遍地删除同一行。我知道我可以构建另一个表并将所有更新的信息插入到该特定情况的BUT中,我需要这些更新的信息返回到同一个表中,以便它可以不断更新自身。
这是我的代码:
DECLARE @MaterialFound TABLE(
MasterRecipeID NCHAR(100),
TempRecipeID NCHAR(100),
TempMaterialID NCHAR(100));
INSERT INTO @MaterialFound
(MasterRecipeID, TempRecipeID, TempMaterialID)
SELECT RecipeID, RecipeID, MaterialID
FROM Recipe
DECLARE @M TABLE(
MRID NCHAR(100),
RID NCHAR(100),
MID NCHAR(100));
--Display table
SELECT MasterRecipeID, TempRecipeID, TempMaterialID FROM @MaterialFound
----------------------------------------------------------------------------
--THIS IS THE IMPORTANT PART--
--LOOP WHILE NOT ALL ARE UPDATED
INSERT INTO @M (MRID, RID, MID)
SELECT (SELECT TOP 1 MasterRecipeID FROM @MaterialFound),
(SELECT TOP 1 RecipeID FROM @MaterialFound),
MaterialID FROM Recipe WHERE RecipeID =
(SELECT TOP 1 TempMaterialID FROM @MaterialFound)
DELETE TOP(1)
FROM @MaterialFound
INSERT INTO @MaterialFound
(MasterRecipeID, TempRecipeID, TempMaterialID)
SELECT (MRID), (MID), MID
FROM @M
DELETE FROM @M
SELECT MasterRecipeID, TempRecipeID, TempMaterialID FROM @MaterialFound
--END LOOP
那么我如何让查询在表格底部插入新行,假设我已经实现了循环?