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 - 2006-04-27 : 19:49:04
|
| I am trying to join a value from 1 table to another... the question I have is mystats is really a fairly large query. select linenumber from CustomerLineNumber, customer.mystats, proc_fkey.mystats. inTotal.mystatsfrom CustomerLineNumber, mystatswhere customerLineNumber.customer = mystats.customerBut myStats looks like this:SELECT CUSTOMER, PROC_FKey, COUNT(BoolCtr) AS inTotalFROM (SELECT CSB_FKey, PROC_FKey, LEFT(CSB_FKey, 5) AS CUSTOMER, PassStatus, 1 AS BoolCtr FROM dbo.TestDynamic WHERE (PassStatus <> 'PASS') AND (TestTime >= '20060121') AND (TestTime < '20060221')) AS myStatsGROUP BY CUSTOMER, PROC_FKeyWhat changes in the first join query so that it includes the result query table ? The following did not WORK :select linenumber from CustomerLineNumber, customer.mystats, proc_fkey.mystats. inTotal.mystatsfrom CustomerLineNumber, ( SELECT CUSTOMER, PROC_FKey, COUNT(BoolCtr) AS inTotalFROM (SELECT CSB_FKey, PROC_FKey, LEFT(CSB_FKey, 5) AS CUSTOMER, PassStatus, 1 AS BoolCtr FROM dbo.TestDynamic WHERE (PassStatus <> 'PASS') AND (TestTime >= '20060121') AND (TestTime < '20060221')) AS myStatsGROUP BY CUSTOMER, PROC_FKey)where customerLineNumber.customer = mystats.customerandrewcw |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-04-27 : 19:53:35
|
Your blue query is a bit unclear, but this should get you started. You have two derived tables in this query. Each derived table must have an alias even if you don't use it. The inner derived table I aliased as t. t isn't used anywhere else.select c.linenumber, mystats.customer, mystats.proc_fkey, mystats.intotalfrom CustomerLineNumber cinner join ( SELECT CUSTOMER, PROC_FKey, COUNT(BoolCtr) AS inTotal FROM ( SELECT CSB_FKey, PROC_FKey, LEFT(CSB_FKey, 5) AS CUSTOMER, PassStatus, 1 AS BoolCtr FROM dbo.TestDynamic WHERE (PassStatus <> 'PASS') AND (TestTime >= '20060121') AND (TestTime < '20060221') ) t GROUP BY CUSTOMER, PROC_FKey) mystatson c.customer = mystats.customer Tara Kizeraka tduggan |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2006-04-27 : 20:06:56
|
| Wow - I am amazed - thanks for your help !!andrewcw |
 |
|
|
|
|
|
|
|