House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  SQL

Combining Queries

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Adam Parker
02/08/2012 02:00 PM

I have a page where I need to combine four queries into one query in order to use the query to build a spreadsheet. I have successfully combined the first three queries and obtain the desired results; however, when trying to incorporate the fourth and final query, I cannot figure out how to do it. My query so far is: select p.partnum, cast(p.partdescription as varchar(100)) as partdescription, sum(w.allocqty) as allocated, sum(w.onhandqty) as onhand, count(j.jobnum) as jobcount, sum(j.requiredqty) as qtyNeeded, sum(j.issuedqty) as qtysent , count(d.ordernum) as ordercount, sum(d.orderqty) as ordered, sum(s.ourinventoryshipqty + s.ourjobshipqty) as shipqty from part p with(nolock), [otherServer].internal.dbo.order_tracker t with(nolock), partwhse w with(nolock), jobmtl j with(nolock) , orderdtl d with(nolock) left join shipdtl s with(nolock) on (d.company = s.company and d.partnum = s.partnum and d.ordernum = s.ordernum) where p.company = '85' and w.company = p.company and j.company = p.company and d.company = p.company and j.partnum = p.partnum and w.partnum = p.partnum and p.partnum = t.partnum and d.partnum = p.partnum group by p.partnum, cast(p.partdescription as varchar(100)) The query I am trying to incorporate is: select partnum, sum(quantity) as recqty from partdtl with (nolock) where PartDtl.Company = '85' and PartDtl.Type = 'Mtl' and PartDtl.Plant = 'MfgSys' and PartDtl.RequirementFlag = 0 and jobnum not like 'MRP%' and PartDtl.partnum in (select partnum from [otherServer].internal.dbo.order_tracker t with(nolock)) group by partnum This is not my strong point, but feel I've made some progress up to now.  Any help or guidance is appreciated.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
George Gallen
02/08/2012 02:44 PM

Can you make it a subquery? select p.partnum, (select partnum, sum(quantity) as recqty......), cast(p.part........ G > To: sql@houseoffusion.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Adam Parker
02/08/2012 03:01 PM

> Can you make it a subquery? select p.partnum, (select partnum, > sum(quantity) as recqty......), cast(p.part........ G I don't know any different to say yes or no.  If I do this, do I simply include the additional select statement in parenthesis?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
George Gallen
02/08/2012 04:02 PM

yes, except only return one value sum(quantity), since your already returning the partnum in the main query. It's probably not the fastest way, but it might be the easiest way. > To: sql@houseoffusion.com ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search sql

May 25, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference