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.
    
        
            
                
                    
                        
                            
                                | Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         stamford 
                                        Starting Member 
                                         
                                        
                                        47 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2014-04-16 : 12:04:49
                                            
  | 
                                             
                                            
                                            I have declare a temporary table @OrgTable and I'm populating it with a single column of strings which represent organisation codes.Prior to populating @OrgTable the codes are part of a continuous string which are delimited by a '|'.I have written a function SplitString to do just that and the individual codes are then inserted into the table.Finally I'm calling a second function, NBOCAP, into which I pass a start date, and end date and each organisation code from @OrgTable so I need to modify my script so it iterates through each organisation code. What form should my script take please? It needs to be backwards compatible with SQL2000.DECLARE @OrgTable TABLE	(		elem varchar(1000)	)INSERT INTO @OrgTableSELECT * FROM SplitString(@OrgCodeString, '|')SELECT * FROM NBOCAP(@StartDate,@EndDate,organisation code)  | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     khtan 
                                    In (Som, Ni, Yak) 
                                     
                                    
                                    17689 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2014-04-16 : 18:13:38
                                          
  | 
                                         
                                        
                                          use the APPLY function SELECT *FROM   @OrgTable       CROSS APPLY NBOCAP(@StartDate,@EndDate,elem) EDIT :  just saw the backward compatibly requirement. You can't use APPLY in 2000. For 2000, best is to everything in a function or to use stored procedure KH[spoiler]Time is always against us[/spoiler]  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |