LEFT JOIN(SELECT iCalendarDayId,ROW_NUMBER() OVER ( ORDER BY dtCalendarDate ) RowNumFROM #x1WHEREiCalendarDayIdIS NOT NULL) AS RowON x1.iCalendarDayId = Row.iCalendarDayId

drop table #x1

Cheers

Andy

==========================================================================================================================A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe