Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Microsoft SQL Server 2008 Programming
This is the forum to discuss the Wrox book Professional Microsoft SQL Server 2008 Programming by Robert Vieira; ISBN: 9780470257029
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Microsoft SQL Server 2008 Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 25th, 2010, 11:48 AM
Authorized User
 
Join Date: Jan 2009
Location: Norway
Posts: 21
Thanks: 5
Thanked 0 Times in 0 Posts
Default Page 55, reference both using CTE

I have just started reading this book, and I really like it a lot!
For every page I read, I'm filling gaps/black holes in my brain:)

But I think that the author is wrong when he on page 55 says that one can't replace both derived tables with a CTE. Actually, you can!
Please take a look at the code below:

USE AdventureWorks2008;
WITH pumps(BusinessEntityID)
AS
(
SELECT sc.PersonID AS BusinessEntityID
FROM Sales.Customer sc
JOIN Sales.SalesOrderHeader AS soh ON sc.CustomerID = soh.CustomerID
JOIN Sales.SalesOrderDetail AS sod ON soh.SalesOrderID = sod.SalesOrderID
JOIN Production.Product AS p ON sod.ProductID = p.ProductID
WHERE p.Name ='Minipump'
),
awc (BusinessEntityID)
AS
(
SELECT sc.PersonID AS BusinessEntityID
FROM Sales.Customer sc
JOIN Sales.SalesOrderHeader AS soh ON sc.CustomerID = soh.CustomerID
JOIN Sales.SalesOrderDetail AS sod ON soh.SalesOrderID = sod.SalesOrderID
JOIN Production.Product AS p ON sod.ProductID = p.ProductID
WHERE p.Name ='AWC Logo Cap'
)
SELECT DISTINCT pp.FirstName, pp.LastName
FROM Person.Person AS pp
JOIN pumps ON pp.BusinessEntityID = pumps.BusinessEntityID
JOIN awc ON awc.BusinessEntityID = pp.BusinessEntityID
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 2 forums, pagination issues page 55-56 kenj BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 0 October 19th, 2009 09:28 PM
Hyperlink on page 55 rhoss BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 July 6th, 2008 01:12 PM
How to use CTE instead of temp table jayaraj123 SQL Server 2005 0 April 25th, 2007 08:03 PM
reference of prev. page in current page kasanar ASP.NET 1.0 and 1.1 Professional 1 February 13th, 2005 01:49 PM
Page 55. Working with 3 projects? BradDotNet BOOK: ASP.NET Website Programming Problem-Design-Solution 1 July 24th, 2003 12:52 PM



All times are GMT -4. The time now is 08:27 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.