title: Loop the select statement in sql server stored procedure
body: <p>I created a store procedure shown below</p>
  
  <pre><code>    CREATE PROCEDURE [dbo].[sp_rptlabelPrint] --'HKOHBLAE11/0007'  ,'','HKO'  
      (                                                          
      @Code varchar(25),
      @Format int=0  ,
      @Branch varchar(25)=''
      )                                                          
      AS                                                        
  
      SELECT 
  
         HB.HB_cCode as HBCode,
         HB.MB_cCode as MBCode,
         PO.PO_cShortName as Dest,
         PS.PO_cShortName as Source
      FROM 
      SHI_HOUSEBLHDR HB
      left join SHI_PORTS PO on HB.PO_cDischargePortCode = PO.PO_cCode 
      left join SHI_PORTS PS on HB.PO_cLoadPortCode = PS.PO_cCode 
  
     where   HB.HB_cCode=@Code and HB.br_ccode=@Branch
  </code></pre>
  
  <p>Here it reurns a single row. 
  But i need to pass a integer value to parameter <code>@Format</code> and if it set to <code>2</code> the select statement must execute 2 times and returns the two rows. If its set 4 it returns 4 times of the same row. is it possible to loop the select statement and return the rows</p>