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 |
mike13
Posting Yak Master
219 Posts |
Posted - 2012-12-18 : 18:55:39
|
Hi All,I'm struggling with this query:SELECT TOP (100) PERCENT dbo.T_Product_Main.CategoryID, dbo.T_Order_Main.CustomerID, dbo.V_Top20_30days.ProductID, dbo.T_Order_Detail.ProductID AS customerproductidFROM dbo.T_Order_Main INNER JOIN dbo.T_Order_Detail ON dbo.T_Order_Main.ORDERID = dbo.T_Order_Detail.OrderID INNER JOIN dbo.T_Product_Main ON dbo.T_Order_Detail.ProductID = dbo.T_Product_Main.id INNER JOIN dbo.V_Top20_30days ON dbo.T_Product_Main.CategoryID = dbo.V_Top20_30days.CategoryID AND dbo.T_Order_Detail.ProductID <> dbo.V_Top20_30days.ProductIDWHERE (dbo.T_Order_Main.CustomerID = 226869)GROUP BY dbo.T_Product_Main.CategoryID, dbo.T_Order_Main.CustomerID, dbo.V_Top20_30days.ProductID, dbo.T_Order_Detail.ProductIDi'm trying that dbo.T_Order_Detail.ProductID <> dbo.V_Top20_30days.ProductIDIt only show productid that are V_Top20_30days and not in T_Order_Detaildoesn't seem to work, i get these results , as you can see product 355 should be there because it is in bothCategoryid customerid productid customerproductid1024 226869 355 24221024 226869 416 3551024 226869 416 24221063 226869 421 20271011 226869 494 27201024 226869 521 355any help, thanks a lot |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-19 : 00:37:30
|
Replace this part (AND dbo.T_Order_Detail.ProductID <> dbo.V_Top20_30days.ProductID) with the following:AND dbo.V_Top20_30days.ProductID NOT IN (SELECT distinct ProductID FROM dbo.T_Order_Detail WHERE Product_id IS NOT NULL)--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
mike13
Posting Yak Master
219 Posts |
Posted - 2012-12-19 : 04:24:51
|
mmm that doesn't produce any result |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-19 : 04:32:40
|
quote: Originally posted by mike13 mmm that doesn't produce any result
Post your complete query once--Chandu |
|
|
mike13
Posting Yak Master
219 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
gtopawb
Starting Member
5 Posts |
Posted - 2012-12-27 : 02:16:17
|
unspammed |
|
|
|
|
|