home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 18,255 of 19,505   
   Henk van den Berg to Erland Sommarskog   
   Re: Help needed to write a qury   
   25 Apr 11 06:50:32   
   
   From: hvandenberg@xs4all.nl   
      
   On 24-04-2011 21:51, Erland Sommarskog wrote:   
   >   
   > WITH numbered AS (   
   >     SELECT EmpID, EmpName, DepartmentID, AllocationDate,   
   >            rowno = row_number() OVER(PARTITION BY EmpID   
   >                                      ORDER BY AllocationDate)   
   > )   
   > SELECT a.EmpID, a.EmpName, a.DepartmentID AS OldDeptID,   
   >         b.DepartmentID AS NewDeptID, a.AllocationDate,   
   >         b.AllocationDate AS TransferDate   
   > FROM   numbered a   
   > JOIN   numbered b ON b.rowno = a.rowno +1   
   > ORDER  BY a.EmpId, a.rowno   
      
   If I copy/paste and run this code, it complains about invalid columnnames.   
   I do notice that there's no reference to a table in the AS (SELECT   
   EmpId...) part, but when I put in the name of the table that I created,   
   I get those invalid columnname errors as well.   
   I'm sure I'm forgetting something very basic, but I can't get it to run.   
   What am I overlooking?   
      
   Best,   
   Henk   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca