Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2009-09-04 : 10:20:19
|
| Orders is a table with customer & id fieldsand I have a nested query that returns Customer,QtyItems. I need the get the QtyItems for each ID..should be just an inner join... BUTThis does NOT work ... Select Orders.Customer,orders.id,QtyItems FROM Orders INNER JOIN( Select Customer, Count(items) as QtyItems From ( .......) AS D Group by Customer) ON Orders.Customer =CustomerIdeas ??? Thanks !!!andrewcw |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-09-04 : 10:23:05
|
| Select Orders.Customer,orders.id,s.QtyItemsFROM Orders INNER JOIN(Select Customer, Count(items) as QtyItemsFrom ( .......) AS DGroup by Customer)s ON Orders.Customer =s.Customer |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2009-09-04 : 11:23:22
|
| I get Incorrect syntax near the keyword 'SELECT'Incorrect syntax near ')'. Not sure why - my query models my sample I posted quite closely - just aggreagate field name different. Ideas ? Thanksandrewcw |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-04 : 11:25:49
|
| Please post the whole query that you tried executing. |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2009-09-04 : 12:01:44
|
| Select CustomerLineNumber.Customer, CustomerLineNumber.LineNumber,S.LNFails FROM CustomerLineNumber innerJoin(SELECT Customer, COUNT(PassStatus) AS LNFAILSFROM (SELECT SUBSTRING(CSB_FKey, 1, 5) AS Customer, PassStatus FROM dbo.TestFlightProcedureDynamic WHERE (PassStatus <> 'PASS') AND (SUBSTRING(CSB_FKey, 1, 1) = 'Y')) AS DGROUP BY Customer) SON CustomerLineNumber.Customer =s.Customerandrewcw |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-04 : 12:11:53
|
there is a space needed between "inner" and "join". Not sure if this is the only problem though.Select CustomerLineNumber.Customer, CustomerLineNumber.LineNumber,S.LNFails FROM CustomerLineNumber inner Join(SELECT Customer, COUNT(PassStatus) AS LNFAILSFROM (SELECT SUBSTRING(CSB_FKey, 1, 5) AS Customer, PassStatusFROM dbo.TestFlightProcedureDynamicWHERE (PassStatus <> 'PASS') AND (SUBSTRING(CSB_FKey, 1, 1) = 'Y')) AS DGROUP BY Customer) SON CustomerLineNumber.Customer =s.Customer |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2009-09-04 : 13:15:20
|
| EEEEK ! THANKS !!! That was it....!!! somehow I had let it come together Thanks all for showing me how to get the data to flow into the inner join.andrewcw |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-04 : 13:52:58
|
| ohh great! you're welcome. |
 |
|
|
|
|
|
|
|