Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Transform Pivot query unknown field concatenate

Author  Topic 

petebob796
Starting Member

35 Posts

Posted - 2007-08-01 : 10:14:34
Im changing a program someone else has written to display an attendance register. It uses a transform pivot query from a table containing attendance for each student for a particular week to display 53 fields numbered 1 to 53. So essentially it is a students attendance over a year plus 1 week overlap.

Anyway I wish to create some reports i.e. display students who haven't attended 3 times in a row (excluding any registers that seem unmarked). I thought the easiest way would be to concatenate fields 1 to 53 inserting an alternative character when a register is unmarked, so that I can jump to an appropriate week by specifying string position.

Unfortunately I have realised if a register hasn't been marked for that week the field won't exist in the pivot table and the program will error. Is there a way to catch this error and continue concatenating the rest or alternatively force the pivot to create all 53 fields.

Any other suggestions much appreciated been stuck on this a while now Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-01 : 10:30:55
Please define the start of week 1.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -