<bdo id='ny3TC'></bdo><ul id='ny3TC'></ul>
      <i id='ny3TC'><tr id='ny3TC'><dt id='ny3TC'><q id='ny3TC'><span id='ny3TC'><b id='ny3TC'><form id='ny3TC'><ins id='ny3TC'></ins><ul id='ny3TC'></ul><sub id='ny3TC'></sub></form><legend id='ny3TC'></legend><bdo id='ny3TC'><pre id='ny3TC'><center id='ny3TC'></center></pre></bdo></b><th id='ny3TC'></th></span></q></dt></tr></i><div id='ny3TC'><tfoot id='ny3TC'></tfoot><dl id='ny3TC'><fieldset id='ny3TC'></fieldset></dl></div>
      <legend id='ny3TC'><style id='ny3TC'><dir id='ny3TC'><q id='ny3TC'></q></dir></style></legend>
    1. <tfoot id='ny3TC'></tfoot>

      <small id='ny3TC'></small><noframes id='ny3TC'>

        Microsoft SQL Server 从选择查询插入

        时间:2023-10-26

        1. <small id='871R8'></small><noframes id='871R8'>

        2. <i id='871R8'><tr id='871R8'><dt id='871R8'><q id='871R8'><span id='871R8'><b id='871R8'><form id='871R8'><ins id='871R8'></ins><ul id='871R8'></ul><sub id='871R8'></sub></form><legend id='871R8'></legend><bdo id='871R8'><pre id='871R8'><center id='871R8'></center></pre></bdo></b><th id='871R8'></th></span></q></dt></tr></i><div id='871R8'><tfoot id='871R8'></tfoot><dl id='871R8'><fieldset id='871R8'></fieldset></dl></div>
          <tfoot id='871R8'></tfoot><legend id='871R8'><style id='871R8'><dir id='871R8'><q id='871R8'></q></dir></style></legend>
            <bdo id='871R8'></bdo><ul id='871R8'></ul>

                  <tbody id='871R8'></tbody>

                  本文介绍了Microsoft SQL Server 从选择查询插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想要做的是:读取日志并将必要的数据插入到 3 个不同的表中,这些表可以相互获取信息.

                  What I'm trying to do: read the logs and insert the necessary data into 3 different tables that get information from each other.

                  LOG_ITEM201303 在游戏日志数据库中找到.
                  Mail_Item_Table, Mail_List_Table, Mail_Message_Table 在游戏数据库中找到.

                  LOG_ITEM201303 is found on gamelogs db.
                  Mail_Item_Table, Mail_List_Table, Mail_Message_Table is found on game db.

                  邮件表通过索引连接.

                  CHAR_KEYNAMEITEMNUM 是我需要用于查询的值.

                  CHAR_KEY, NAME, ITEMNUM are the values I need to use for my queries.

                  我从日志中获取数据的查询:

                  The query for me to get the data from the logs:

                  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+):

                  Sample result of logs query above(total actual results are in 600+):

                   CHAR_KEY        NAME            ITEMNUM
                   -----------+----------------+-----------
                   28257      |   clarkailey   |   14438
                   894367     |   Wolf         |   15023
                   2869858    |   HOPEINME     |   14437
                  

                  现在我需要自动将每一行插入到这个查询中:

                  Now I need to automatically insert each row into this query:

                   CHAR_KEY        NAME            ITEMNUM
                   -----------+----------------+-----------
                   2869858    |   HOPEINME     |   14437
                  

                  (此查询显示了上面插入的第三个示例数据的示例...
                  有没有办法更快地完成此操作,而不是为每个条目进行此查询?)

                  (this query shows an example of the 3rd sample data above being inserted...
                  instead of making this query for each entry is there a way for this to done faster?)

                  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())
                  

                  我的问题:

                  如何自动化这一切,即查询将读取所有日志并逐行插入数据.非常感谢.

                  How to automate all this, that the query will read all the logs and insert the data row by row. Thank you very much.

                  我可以为此使用@variables吗?

                  Can I use @variables for this?

                  推荐答案

                  您可以使用以下语法进行插入

                  You can use the following syntax for inserts

                  INSERT INTO dbo.Destination (Col1, Col2, Col3)
                  SELECT Col1, Col2, Col3
                  FROM dbo.Source
                  

                  如果您的表具有与目标相同的列或结果集具有与目标相同的列,则不必在 INSERT 中指定列.

                  If you had tables with the same columns or a result set that had the same columns as your destination, you don't have to specify columns in the INSERT.

                  INSERT INTO dbo.Destination
                  SELECT *
                  FROM dbo.Source
                  

                  这两个都基于已创建的 Destination 表.这些SELECT * INTO dbo.Destination FROM dbo.Source

                  Both of these are predicated on your Destination table already being created. These are NOT the same as SELECT * INTO dbo.Destination FROM dbo.Source

                  这篇关于Microsoft SQL Server 从选择查询插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:SQLite:将值列表绑定到“WHERE col IN (:PRM)"; 下一篇:选择没有重复条目的一行

                  相关文章

                  <tfoot id='2lE5U'></tfoot>

                  <i id='2lE5U'><tr id='2lE5U'><dt id='2lE5U'><q id='2lE5U'><span id='2lE5U'><b id='2lE5U'><form id='2lE5U'><ins id='2lE5U'></ins><ul id='2lE5U'></ul><sub id='2lE5U'></sub></form><legend id='2lE5U'></legend><bdo id='2lE5U'><pre id='2lE5U'><center id='2lE5U'></center></pre></bdo></b><th id='2lE5U'></th></span></q></dt></tr></i><div id='2lE5U'><tfoot id='2lE5U'></tfoot><dl id='2lE5U'><fieldset id='2lE5U'></fieldset></dl></div>
                • <small id='2lE5U'></small><noframes id='2lE5U'>

                  <legend id='2lE5U'><style id='2lE5U'><dir id='2lE5U'><q id='2lE5U'></q></dir></style></legend>

                        <bdo id='2lE5U'></bdo><ul id='2lE5U'></ul>