Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.28 KB | None | 0 0
  1. SELECT Agent.exid, afName, fshortName,
  2.         cast(AmountM as int) AmountM,
  3.         cast(AmountC as int) AmountC,
  4.                 ordersc.ordate
  5.         --cast(Sum(orSumRoubles) as money) Sum
  6.  FROM (SELECT DS_ORDERS.MasterFID, Mfid, orSumRoubles, Sum(Amount) AmountM
  7.        FROM DS_ORDERS, DS_Orders_Items, DS_ITEMS, DS_ObjectsAttributes
  8.        Where orDate >= '2011-01-05 00:00:00.000' and  orDate < '2011-10-05 00:00:00.000'
  9.              and DS_ORDERS.orid      = DS_Orders_Items.orid
  10.              and DS_ORDERS.MasterFID = DS_Orders_Items.MasterFID
  11.              and DS_ITEMS.iID        = DS_Orders_Items.iID
  12.              and DS_ObjectsAttributes.Activeflag = 1
  13.              and DS_ITEMS.Activeflag = 1
  14.              and AttrValueId in (5220009)
  15.              and DS_ObjectsAttributes.Id = DS_ITEMS.iid
  16.              and orType in (1,2) and Condition = 1
  17.        Group by DS_ORDERS.MasterFID, Mfid, orSumRoubles) as OrdersM,
  18.  
  19.        (SELECT ordate, DS_ORDERS.MasterFID, Mfid, orSumRoubles, Sum(Amount) AmountC  
  20.        FROM DS_ORDERS, DS_Orders_Items, DS_ITEMS, DS_ObjectsAttributes
  21.        Where orDate >= '2011-01-05 00:00:00.000' and  orDate < '2011-10-05 00:00:00.000'
  22.              and DS_ORDERS.orid      = DS_Orders_Items.orid
  23.              and DS_ORDERS.MasterFID = DS_Orders_Items.MasterFID
  24.              and DS_ITEMS.iID        = DS_Orders_Items.iID
  25.              and DS_ObjectsAttributes.Activeflag = 1
  26.              and DS_ITEMS.Activeflag = 1
  27.              and AttrValueId in (5220010)
  28.              and DS_ObjectsAttributes.Id = DS_ITEMS.iid
  29.              and orType in (1,2) and Condition = 1
  30.        Group by ordate,DS_ORDERS.MasterFID, Mfid, orSumRoubles) as OrdersC,
  31.  
  32.       (SELECT fid, exid, fName as afName  
  33.        From DS_Faces Where ftype = 4 and fActiveFlag = 1) as Agent,
  34.       (SELECT DS_Faces.fid, fshortName, Mfid, MasterFID
  35.        From DS_Faces, MobFaces
  36.        Where ftype = 7 and MFactiveflag = 1 and fActiveFlag = 1
  37.              and MobFaces.Mfid  = DS_Faces.fid)  as Faces
  38. Where     OrdersM.MasterFID   = Agent.fid
  39.           and OrdersC.MasterFID   = Agent.fid  
  40.           and OrdersM.Mfid    =* Faces.fid
  41.           and OrdersC.Mfid    =* Faces.fid      
  42.           and Faces.MasterFID  = Agent.fid  
  43.           --and Agent.exid = 260502          
  44. Group by Agent.exid, afName, fShortName, AmountM, AmountC, ordersc.ordate
  45. Order by afName, fShortName, ordate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement