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-05-04 : 21:55:31
|
| I have been shown thank to help from this forum how to take 2 tables and find the the records that are unique to the other like this:SELECT t.linenrFROM statlineNrTest tLEFT OUTER JOIN StatLineNrProced pON t.linenr = p.linenrWHERE p.linenr IS NULLHowever statlineNrTest can be found as the result of a query :When I try to insert the result set I get errors, may be its not possible or I dont know the syntax to get it done. ( I suspect my ignorance ) What do you think ?? ThanksSELECT tt.linenrFROM SELECT FROM ( insert the query below between the parenthesis ) as ttLEFT OUTER JOIN StatLineNrProced pON t.linenr = p.linenrWHERE p.linenr IS NULL... the messy query that drives the inner query would be :SELECT c.LineNumber, mystats.CUSTOMER, mystats.PROC_FKey, mystats.inTotalFROM dbo.CustomerLineNumber AS c INNER 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')) AS t GROUP BY CUSTOMER, PROC_FKey) AS mystats ON c.Customer = mystats.CUSTOMERandrewcw |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-04 : 22:02:04
|
What is the error you are getting ? KH |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2006-05-04 : 23:00:55
|
| 2 errors : incorrect syntax near the keyword selectincorrect syntax near the keyword asandrewcw |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-04 : 23:09:12
|
[code]SELECT a.linenrFROM ( SELECT * FROM ( insert the query below between the parenthesis ) as tt) as aLEFT OUTER JOIN StatLineNrProced pON t.linenr = p.linenrWHERE p.linenr IS NULL[/code]If you still have problem, post the complete query used rather than section by section KH |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2006-05-05 : 11:04:04
|
| I inserted the query per the pattern you showed but I get :the column prefix 't' does not match with a table name or alias name used in the query . I thought it might refer to this part of the query : LEFT OUTER JOIN StatLineNrProced p ON t.linenr = p.linenr WHERE p.linenr IS NULL If I change that instance of t.linenr to a.linenr then I get 2 instances of invalid linenr. If I try tt.linenr at that location I get the same error I had with t.linenrSELECT a.linenr FROM ( SELECT * FROM ( SELECT c.LineNumber, mystats.CUSTOMER, mystats.PROC_FKey, mystats.inTotalFROM dbo.CustomerLineNumber AS c INNER 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')) AS t GROUP BY CUSTOMER, PROC_FKey) AS mystats ON c.Customer = mystats.CUSTOMER) as tt ) as a LEFT OUTER JOIN StatLineNrProced p ON t.linenr = p.linenr WHERE p.linenr IS NULLandrewcw |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-05 : 11:14:17
|
[code]LEFT OUTER JOIN StatLineNrProced p ON a.linenr = p.linenr WHERE p.linenr IS NULL[/code]EDIT : removed t and change to a KH |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2006-05-05 : 11:27:22
|
| Hi Khtan,what does the strange red symbol indicate ? LEFT OUTER JOIN StatLineNrProced p ON a.linenr = p.linenr WHERE p.linenr IS NULL If that is what it means, that gave me the 2 instances of invalid linenrandrewcw |
 |
|
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2006-05-05 : 23:52:16
|
| I am embarrassed ! When I compared the small pattern against my actual query I noticed the field Name was different : Now it works great !!!SELECT a.LineNumber FROM (SELECT c.LineNumber, mystats.CUSTOMER, mystats.PROC_FKey, mystats.inTotal FROM dbo.CustomerLineNumber AS c INNER 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')) AS t GROUP BY CUSTOMER, PROC_FKey) AS mystats ON c.Customer = mystats.CUSTOMER) AS a LEFT OUTER JOIN dbo.statLineNrProced AS p ON a.LineNumber = p.lineNrWHERE (p.lineNr IS NULL)Thanks for your patience with me :)andrewcw |
 |
|
|
|
|
|
|
|