有条件地检查和更新表

时间:2016-10-17 06:25:44

标签: sql sql-server tsql

该公司有一个SQL表[Tatkal_Merge],其中包含多个具有多个帐户的分支。

每当新帐户添加到分支机构时,都会扫描并为每个帐户分派一个工具包。

每当完成对特定分支的帐户的所有扫描时,分支将被标记为已完成并带有时间戳。

  

[br_complete_qc] =' Y',br_complete_Qc_date = GETDATE()

目前,我们使用以下代码执行相同的操作:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace ShaderTest {
    /// <summary>
    /// This is the main type for your game.
    /// </summary>
    public class Game1 : Game {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Effect shader1;
        Texture2D peach;

        public Game1() {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize() {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent() {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            shader1 = Content.Load<Effect>("shader1");
            peach = Content.Load<Texture2D>("peach");

        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// game-specific content.
        /// </summary>
        protected override void UnloadContent() {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime) {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime) {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            shader1.CurrentTechnique.Passes[0].Apply();
            spriteBatch.Draw(peach, new Vector2(0, 0), Color.White);

            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

数据日期是Nvarchar。例如:2016-10-16。

帐户号码是主键。

目前,代码需要时间来执行。

获得它的更好/更正确的方法是什么?

1 个答案:

答案 0 :(得分:0)

AVOID子查询,因为子查询会减慢执行

  declare @dateBrcode varchar (100)
  select distinct @dateBrcode =   data_date+br_code FROM
  [Tatkal].[dbo].     [Tatkal_Merge] where pin_scan='N'
  declare @actno varchar(100)
  select @actno =  act_no 
  FROM [Tatkal].[dbo].[Tatkal_Merge] 
  where [br_complete_qc]='N' and 
  data_date+br_code not in (@dateBrcode)

 update Tatkal_Merge set [br_complete_qc]='Y',
 br_complete_Qc_date=GETDATE()  where act_no in (@actno)