sql - How do I store Subquery result in variable and use in master query -


I need to put in the subquery result variable and in the master query to save the execution time of the query Otherwise I would have to use the same subquery code for this:

  Select different conversions (DataTime, Authoring (O transact Time, 0 to 9), 112) + convert (Dettaim, authoring (o. Tronssettaim, 10, LAN (O.transacttime)), 114), o.clordid, ack.strategyid, o.Account, o.AllocAccount, o. Symbol, o.price, ISNULL ((order Select the top 1 L.orderqty order_msgs_incoming1 L where o.clordid = L. Clordid and El.am.amji_aid these (17,18, 1 9, 22, 59, 44) Order by L Tronsstakt time Diissi), o. Orktiti) Orderkit, O Incorporated, (Select ISNULL (Order (Top 1L Order Order_Jays_Ining1L), where O.Clordid = L. Clustid and LMM_ID in (17,18, 19, 22, 59, 44) L. Tronsekttaim order by Diissi), o. Orktiti) -sm (ex., Aisanyuelel ((LAC Tronsakttaim Diissi the order-Mjis_ining 1 L in order by the Okclordid = L. Clordid and El.am.amji_aid (17,18, 19, 22, 59, 44) In order to select the top 1 L order. The switch to), Orekranti)) Order_msgs_incoming is & lt; TblIndx & gt; East, where o.Clordid = ex.clordid) strategy after choosing ack lines to order the remaining order_msgs_incoming1 o / * Strategy Update I 43 For the vacant but 46 * the population is o / o to order in order to leave the exterior - MMSG_Ining 1 AK o.clordid = ack.clordid and ack.msg_id = 46 where / * line only for new order because it contains all Column values ​​include * / o.msg_id = 43  

I must have such a sort Is

  SELECT DISTINCT variableValue = ISNULL ((Ordr_ top 1 L msgs_incoming1 L. Select the ordering where o.clordid = L.clordid and L.msg_id (17,18,19,22,59,44) order by el. Transact DESC), O Sarkshi) Orders, O Inkorfad (Selestalual (variable value-even (former. Letshers), variable value) order_msgs_incoming & LT; TblIndx & gt; in the past where o.Clordid = ex.clordid) order_msgs_incoming1 o  

Balance from Please help me

You can declare a variable and assign it a value using SELECT clause. Then use the variable in your master query. Please find the code given below:

  DECLARE @variableValue bit; SELECT @variableValue = ISNULL (Order 17, 18, 19, 22, 59, 44) Order by LA Transacttime DESC) Order-MMSGiningIn 1L OECLORDID = L. Top1 L from Clordid and LMM_ID O.orderqty) from order_msgs_incoming1 o Select DISTINCT @variableValue as orders, o.InClOrdID, (SELECT ISNULL (variableValue- sum (ex.LastShares), variableValue) & Tt from Adesh_ms gs_incoming; TblIndx; pre WHERE o.Clordid = ex. Clordid) Balance FROM You can use it in a variable so that you can use the following code to replace the subquery:  
  SELECT TOP 1 L order_ms gs_incoming1 Join L INN order_msgs_incoming1 o L. ONclordid = L.clordid and L.msg_id (17,18,19,22,59,44) by ORD ER. Transact Time Time DESC  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -