Sponsored by: Bodybuilding Warehouse - Amazing prices and FREE P&P on bodybuilding supplements from Gaspari, Nutrex, BSN NO-Xplode, Animal Pak & more!

 SQL statement issue


Change Page: < 12 | Showing page 2 of 2, messages 21 to 26 of 26
Author Message
gwilym

  • Total Posts : 3126
  • Reward points : 6234
  • Joined: 25/10/2004
  • Status: offline
  • Read my TROG
Re:SQL statement issue 31 January 2012 11:44 (permalink)
OK, i might be completely wrong now, but try separating them within the same script, but giving them individual identities.
 
Then at the end of the query, join the 2 parts together using the join you want to.
 
So in essence you have 3 individual queries within the same script.
 
 
Where I think you're going wrong is trying to include the
 
(SELECT orderid, op.ordprodname, op.ordprodid, SUM(op.ordprodqty) AS qty FROM isc_orders o JOIN isc_order_products op on op.orderprodid=o.orderid WHERE orddate BETWEEN 1271853079 AND 1272637707 GROUP BY op.ordprodid) AS qty,
 
part as a sub query.

Official MaxiRAW Board Representative 

 

   High-quality, tested performance nutrition.
 Quality assurance & value guaranteed...
www.maxiraw.com  

Twitter: @MaxiRAW     Tag: #Rawdedication

 
#21
    Bodybuilding Warehouse Bodybuilding Warehouse - The best bodybuilding supplements from the best brands, Boditronics, CNP Professional, Nutrisport & more all with free delivery!
    Tony Barnes

    • Total Posts : 17383
    • Reward points : 6637
    • Joined: 07/10/2004
    • Location: Leeds
    • Status: offline
    • Read my TROG
    Re:SQL statement issue 31 January 2012 12:03 (permalink)
    Yep, defo that bit as a sub query that is cocking it up! Can't figure out how to join them as seperate ones though...
     
    Bah, will leave for a bit, other stuff to do!!
     
    Ta for input so far
     
    #22
      gwilym

      • Total Posts : 3126
      • Reward points : 6234
      • Joined: 25/10/2004
      • Status: offline
      • Read my TROG
      Re:SQL statement issue 31 January 2012 13:05 (permalink)
      No worries man. Give us an update when you've sorted it, would be interested to see the solution.

      Official MaxiRAW Board Representative 

       

         High-quality, tested performance nutrition.
       Quality assurance & value guaranteed...
      www.maxiraw.com  

      Twitter: @MaxiRAW     Tag: #Rawdedication

       
      #23
        Tony Barnes

        • Total Posts : 17383
        • Reward points : 6637
        • Joined: 07/10/2004
        • Location: Leeds
        • Status: offline
        • Read my TROG
        Re:SQL statement issue 31 January 2012 14:41 (permalink)
        lol, you might be waiting a while..!!
         
        #24
          M1ST

          • Total Posts : 231
          • Reward points : 2581
          • Joined: 19/08/2009
          • Status: offline
          • Read my TROG
          Re:SQL statement issue 31 January 2012 21:19 (permalink)
          Definately go for a JOIN rather than subquery. You'll get a much better query plan too.
           
          What does the estimated query plan show? If it's SQL 2008 R2 you may get a useful query optimsation tip...
           
          #25
            mcsdan

            • Total Posts : 192
            • Reward points : 2385
            • Joined: 11/06/2009
            • Location: somewhere in Essex
            • Status: offline
            • Read my TROG
            Re:SQL statement issue 01 February 2012 15:55 (permalink)
            (SELECT orderid, op.ordprodname, op.ordprodid, SUM(op.ordprodqty) AS qty FROM isc_orders o JOIN isc_order_products op on op.orderprodid=o.orderid WHERE orddate BETWEEN 1271853079 AND 1272637707 GROUP BY op.ordprodid) AS qty
             
            Shouldn't this have all non aggregate fields in the group clause:-
             
            group by orderid,op.ordprodname, op.ordprodid 
             
            ie
              (SELECT orderid, op.ordprodname, op.ordprodid, SUM(op.ordprodqty) AS qty FROM isc_orders o JOIN isc_order_products op on op.orderprodid=o.orderid WHERE orddate BETWEEN 1271853079 AND 1272637707 group by orderid,op.ordprodname, op.ordprodid) AS qty
             
             
            <message edited by mcsdan on 01 February 2012 16:04>
             
            #26
              Share/Bookmark
              Change Page: < 12 | Showing page 2 of 2, messages 21 to 26 of 26


              James' Super Smoothie
              Jump to:

              Current active users

              There are 0 members and 2 guests.

              Icon Legend and Permission

              • New Messages
              • No New Messages
              • Hot Topic w/ New Messages
              • Hot Topic w/o New Messages
              • Locked w/ New Messages
              • Locked w/o New Messages
              • Read Message
              • Post New Thread
              • Reply to message
              • Post New Poll
              • Submit Vote
              • Post reward post
              • Delete my own posts
              • Delete my own threads
              • Rate post

              2000-2012 ASPPlayground.NET Forum Version 3.9
              Go To Top Of Page