Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2007, 12:14 PM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code in Book Not Working

I was told that the author of the book mentioned below recently ran this query and it worked. I don't see how:

I've been trying to run code found on page 144 of the "Professional SQL Server 2005 Programming" book for the last 2 days.

--Using AdventureWorks database
SELECT c.LastName,
ISNULL(CAST(SELECT MIN(OrderDate)
FROM Sales.SalesOrderHeader o
WHERE o.ContactID = c.ContactID)AS varchar), ' Never Ordered')
AS 'Order Date'
FROM Person.Contact c

I get the error:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ')'.

I've tried modify this query to no end and can't figure out what's wrong. Please help.

Kim Avery
 
Old April 11th, 2007, 12:54 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try putting parenthesis around the select statement, like...
SELECT
      c.LastName
    , ISNULL(CAST((SELECT MIN(OrderDate) FROM Sales.SalesOrderHeader o WHERE o.ContactID = c.ContactID) AS varchar), ' Never Ordered') 'Order Date'
FROM Person.Contact c

HTH

Adam Gossage
Lake Wylie, SC, USA
 
Old April 11th, 2007, 01:29 PM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. I was putting parenthesis everywhere, but apparently not there. Thanks again.

Kim

Quote:
quote:Originally posted by agossage
 Try putting parenthesis around the select statement, like...
SELECT
     c.LastName
    , ISNULL(CAST((SELECT MIN(OrderDate) FROM Sales.SalesOrderHeader o WHERE o.ContactID = c.ContactID) AS varchar), ' Never Ordered') 'Order Date'
FROM Person.Contact c

HTH

Adam Gossage
Lake Wylie, SC, USA
Kim Avery





Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with the book on two machines... Bruce.Wiki BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 October 30th, 2008 11:53 AM
SQL In book not working bgcsocal SQL Server 2005 3 August 5th, 2008 12:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.