title: stored procedure to generate a 16 digit random number and store it for each of the user for each of the bank
body: <p>Stored procedure to generate a 16 digit random number and store it for each of the user for each of the bank for each of the card type(debit,credit) and for each of the card name(master, visa). Please check what is getting wrong..
  Only the loop for each for bank is working properly. while the other loops for card type and card name are not working and information is getting stored for only one card type and one card name.. Please check where am i getting wrong..</p>
  
  <pre><code>ALTER PROCEDURE dbo.storecardinfo(@uer_id INT)
      /*
      (
      @parameter1 int = 5,
      @parameter2 datatype OUTPUT
      )
      */
  
  
  AS
  /* SET NOCOUNT ON */
  declare
  @c_type_id int ,    
  @c_name_id int  ,
  @b_id int , 
  @c_name varchar(50) ,
  @c_type varchar(50) ,
  @b_name varchar(50),
  @rand_no varchar(50)
  begin
  set @c_type_id=(select min(card_type_id)  from tbl_card_type);
  set @c_name_id=( select min(card_id) from tbl_card_master);
  set @b_id=(select min(bank_id) from tbl_bank_master);
  while @c_type_id is not null
  begin
  while @c_name_id is not null
  begin
  while @b_id is not null
  begin
  set @c_name=(select card_name from tbl_card_master where card_id=@c_name_id);
  set @c_type=(select card_type_name from tbl_card_type where card_type_id=@c_type_id);
  set @b_name=(select bank_name from tbl_bank_master where bank_id=@b_id);
  set @rand_no=(SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
  + (DATEPART(ss, GETDATE()) * 1000 )
  + DATEPART(ms, GETDATE()) ));
  insert into tbl_card_info(user_id,card_name,card_type,card_bank,card_number) values(@uer_id,@c_name,@c_type,@b_name,@rand_no);
  
  set @b_id=(select min(bank_id) from tbl_bank_master where (@b_id&lt;bank_id));
  end
  set @c_name_id=(select min(card_id) from tbl_card_master where (@c_name_id&lt;card_id));
  end
  set @c_type_id=(select min(card_type_id) from tbl_card_type where (@c_type_id&lt;card_type_id));
  end
  end
  </code></pre>