Susan Harkins
harkinsss at bellsouth.net
Sun Feb 19 15:51:17 CST 2006
Would someone please run this in Express and see if you get the same error I do? The Tech Editor says it works for him, but I'm getting an error that there's no DepartmentID column in the Employee table. I checked, and it isn't there. I don't know whether the TE's goofy or I'm just doing something wrong. Thanks! Susan H. DECLARE @departmentid int, @name nvarchar(50) DECLARE @nemployees int DECLARE department_cursor CURSOR LOCAL SCROLL STATIC FOR SELECT DepartmentID, Name FROM HumanResources.Department OPEN department_cursor PRINT 'Results for ' + CAST(@@CURSOR_ROWS AS varchar) + ' departments' Print '-------------' FETCH NEXT FROM department_cursor INTO @departmentid, @name SELECT @nemployees = ( SELECT COUNT(*) FROM HumanResources.Employee WHERE DepartmentID = @departmentid) PRINT @name + ' has ' + CAST(@nemployees AS varchar) + ' employees' WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM department_cursor INTO @departmentid, @name SELECT @nemployees = ( SELECT COUNT(*) FROM HumanResources.Employee WHERE DepartmentID = @departmentid) PRINT @name + ' has ' + CAST(@nemployees AS varchar) + ' employees' END CLOSE department_cursor DEALLOCATE department_cursor