Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i'm doing the project in that store the same name records,so i want to add the suffix for all record as like Comp1,Comp2...Comp10.
Posted
Comments
Mehdi Gholam 2-Nov-11 2:27am    
And your problem is?

create procedure to insert data in database., call the proc from your code with appropriete params.


SQL
create proc myInsertProc
Begin
  
  //first get the matching records, with the query ilke
  
  select count(1) into variable1 from table1 where column1 like 'Comp%';

   if variable1 > 0
      variable2 = 'Comp' + variable1;
   else  
      variable2 = 'Comp';
   end if;
   
   insert into table1 (column1) values (variable2);
End
 
Share this answer
 
I also agree with Mehdi Gholam, this problem is very ordinary, you can convert each record (in constant) to string and adding it a counter (in loop) for generate its!


I wrote this recursive function and you can use it for generate:
C#
string f(string ConstStr, int from, int to)
{
    if (to == from)
        return ConstStr + from + ",";
    else
        return f(ConstStr, from, to - 1) + ConstStr + to + ",";
}


Finally, you can pharse the sentence with "," like this:
C#
string str = f("Mehdi", 1, 5);
string[] strArr = str.Split(new char[] { ',' });
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900