Wrox Programmer Forums
|
BOOK: Beginning SQL Server 2005 Programming ISBN: 978-0-7645-8433-6
This is the forum to discuss the Wrox book Beginning SQL Server 2005 Programming by Robert Vieira; ISBN: 9780764584336
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning SQL Server 2005 Programming ISBN: 978-0-7645-8433-6 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 February 16th, 2007, 05:36 PM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Function problem - pages 419-420

Hi...

I have created function and I have tried to run it forEmployeeID = 2 - query runs forever without the results.
Below is a code I have used for the function:

CREATE FUNCTION dbo.fnGetReports
  (@EmployeeID AS int)
  RETURNS @Reports TABLE
  (
  EmployeeID int NOT NULL,
  ReportsToID int NULL
  )

AS
BEGIN

DECLARE @Employee AS int

INSERT INTO @Reports
   SELECT EmployeeID, ReportsTo
   FROM Employees
   WHERE EmployeeID = @EmployeeID

SELECT @Employee = MIN(EmployeeID)
FROM Employees
WHERE ReportsTo = @EmployeeID

WHILE @EmployeeID IS NOT NULL
   BEGIN
      INSERT INTO @Reports
      SELECT *
      FROM fnGetReports(@Employee)

      SELECT @Employee = MIN(EmployeeID)
      FROM Employees
      WHERE EmployeeID > @Employee AND ReportsTo = @EmployeeID
   END

RETURN

END
GO

After function has been created...

SELECT * FROM fnGetReports(2)

Anybody with the same experience and solution - please help

marek





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with two pages launching Diggers33 Flash (all versions) 2 January 25th, 2007 07:39 AM
2 pages.....one problem. cincinnaticj7 Classic ASP Databases 1 January 26th, 2005 02:07 PM
Tap Pages Problem kfls_83 ADO.NET 0 November 21st, 2004 07:54 AM
Problem using AppendText with Tab pages sis C# 3 February 16th, 2004 05:59 PM
Problem resfreshing web pages pkgal79 HTML Code Clinic 3 June 13th, 2003 07:59 AM





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