我试图让这个查询在选择的所有结果上运行。
但问题是 select fromLOG_ITEM201303
只返回一个结果。
所以这意味着INSERT INTO
每次我运行这个脚本时,该子句只影响一行。
但我想要做的是获得所有结果(总共 600 多个)并逐行插入所有结果。
DECLARE @charkey int, @charname varchar(16), @item int
SELECT @charkey = CHAR_KEY, @charname = NAME, @item = ITEMNUM
FROM LOG_ITEM201303
where
(
ITEMNUM = 14317
OR ITEMNUM = 14318
OR ITEMNUM = 15478
OR ITEMNUM = 15479
OR ITEMNUM = 14301
OR ITEMNUM = 14302
OR ITEMNUM = 15476
OR ITEMNUM = 15477
OR ITEMNUM = 15018
OR ITEMNUM = 15019
OR ITEMNUM = 15020
OR ITEMNUM = 15021
OR ITEMNUM = 15022
OR ITEMNUM = 15023
OR ITEMNUM = 15024
OR ITEMNUM = 15025
OR ITEMNUM = 14437
OR ITEMNUM = 14438
OR ITEMNUM = 15656
OR ITEMNUM = 15657
OR ITEMNUM = 15658
OR ITEMNUM = 15659
OR ITEMNUM = 15660
OR ITEMNUM = 15661
OR ITEMNUM = 15662
OR ITEMNUM = 15663
) AND (KIND = 133) AND (Convert(varchar, OCCUR_TIME,111) < '2013/03/22')
SELECT @charkey, @charname, @item
INSERT INTO game.dbo.Mail_Item_Table
(ItemNumber, ItemInfo, ReceiveDate)
VALUES
(@item, (SELECT CONVERT(BINARY(16), REVERSE(CONVERT(BINARY(16), @item)))), NULL)
INSERT INTO game.dbo.Mail_Message_Table
(Message)
VALUES
('Automated Message from the ADMIN.')
INSERT INTO game.dbo.Mail_List_Table
(ReceiverCharKey, MailListIndex, MailItemIndex, MailMessageIndex, Sender, Receiver, SendDate)
VALUES
(@charkey,
(SELECT TOP 1 MailListIndex+1 as last_entry
FROM game.dbo.Mail_List_Table
WHERE sender = 'SEND0R'
ORDER BY MailListIndex DESC),
(SELECT TOP 1 MailItemIndex AS last_entry
FROM game.dbo.Mail_Item_Table
ORDER BY MailItemIndex DESC),
(SELECT TOP 1 MailMessageIndex AS last_entry
FROM game.dbo.Mail_Message_Table
ORDER BY MailMessageIndex DESC),
'SEND0R', '@charname', getdate())