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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Combining Result with CTE

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2010-09-29 : 01:52:20
hi

I have a tracking table that tracks products. It has a prodid and productname field. Presume i have 3 products tracked,
1, Apple
2, Orange
3, Pear

So i wrote a stored proc to list out their details but it always show only pears. This is my code:

Create Proc [dbo].[tracking]

@ProductName nvarchar(50)

With TrackProd AS
(
Select ProdID, Productname from Tracking where Productname = @ProductName
)

SELECT ProductName , ProdDesc, ProdPrice, ProdQuantity From Product inner join TrackProd on Product .ProdID = TrackProd.PrdID

I know it can be done simply without CTE and join them based on their prodid. But because of the complexities, i need to use CTE. The solution of the example will allow me to combine CTE results in my actual enviroments. sorry for the inconveniences. Thanks

How to show all products? thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-09-29 : 04:25:12
LEFT JOIN.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2010-09-30 : 02:16:48
Thanks
Go to Top of Page
   

- Advertisement -