[dba-SQLServer] code not working

Jim Lawrence accessd at shaw.ca
Sun Feb 19 19:42:32 CST 2006


Susan, just off the top; are the setting set to case sensitive?

Jim

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Susan
Harkins
Sent: February 19, 2006 1: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




More information about the dba-SQLServer mailing list