我正在尝试做的事情:阅读日志并将必要的数据插入到 3 个不同的表中,这些表可以相互获取信息。
LOG_ITEM201303
在游戏日志数据库中找到。
Mail_Item_Table
, Mail_List_Table
,Mail_Message_Table
在游戏数据库中找到。
邮件表通过索引连接。
CHAR_KEY
, NAME
,ITEMNUM
是我需要用于查询的值。
我从日志中获取数据的查询:
SELECT CHAR_KEY, NAME, 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')
上面的日志查询示例结果(总实际结果在600+):
CHAR_KEY NAME ITEMNUM
-----------+----------------+-----------
28257 | clarkailey | 14438
894367 | Wolf | 15023
2869858 | HOPEINME | 14437
现在我需要自动将每一行插入到这个查询中:
CHAR_KEY NAME ITEMNUM
-----------+----------------+-----------
2869858 | HOPEINME | 14437
(此查询显示了上面插入的第三个示例数据的示例......
而不是对每个条目进行此查询有没有办法更快地完成?)
INSERT INTO Mail_Item_Table
(ItemNumber, ItemInfo, ReceiveDate)
VALUES
(14437, --this is the ITEMNUM
(SELECT CONVERT(BINARY(16), REVERSE(CONVERT(BINARY(16), 14437)))), NULL)
INSERT INTO Mail_Message_Table
(Message)
VALUES
('Automated Message from the ADMIN.')
INSERT INTO Mail_List_Table
(ReceiverCharKey, MailListIndex, MailItemIndex, MailMessageIndex, Sender, Receiver, SendDate)
VALUES
(2869858, --this is the CHAR_KEY
(SELECT TOP 1 MailListIndex+1 as last_entry
FROM Mail_List_Table
WHERE sender = 'SENDER'
ORDER BY MailListIndex DESC),
(SELECT TOP 1 MailItemIndex AS last_entry
FROM Mail_Item_Table
ORDER BY MailItemIndex DESC),
(SELECT TOP 1 MailMessageIndex AS last_entry
FROM Mail_Message_Table
ORDER BY MailMessageIndex DESC),
'SENDER',
'HOPEINME', --this is the NAME
getdate())
我的问题:
如何自动化这一切,即查询将读取所有日志并逐行插入数据。非常感谢。
我可以为此使用@variables 吗?