[dba-SQLServer] code not working

Nancy Lytle word_diva at hotmail.com
Sun Feb 19 17:10:06 CST 2006


I ran it in SQL2005 (not express) and got the same error:
Msg 207, Level 16, State 1, Line 32
Invalid column name 'DepartmentID'.
Msg 207, Level 16, State 1, Line 50
Invalid column name 'DepartmentID'

Nancy 

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan
Harkins
Sent: Sunday, February 19, 2006 4:51 PM
To: SQLList
Subject: [dba-SQLServer] code not working

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


_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.10/263 - Release Date: 2/16/2006
 



More information about the dba-SQLServer mailing list