Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to run this command several times with different ids

Exec dbs_sp_applyrule2_helo + id1
Exec dbs_sp_applyrule2_helo + id2
Exec dbs_sp_applyrule2_helo + id3
Exec dbs_sp_applyrule2_helo + id4
.
.
.
.
Exec rbs_sp_applyrule2_mtbc + id50

Note: ids is a number always different
Posted
Comments
_Asif_ 16-Jan-15 2:30am    
What have you tried so far?
Niju1 16-Jan-15 11:30am    
for where you get id? if from a table create another procedure to to call this procedure in a loop

Try this:
C#
using (SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE"))
using (SqlCommand command = new SqlCommand("dbs_sp_applyrule2_helo", connection))
{
    command.CommandType = CommandType.StoredProcedure;
    
    SqlParameter idParameter = command.Parameters.Add("@ID", SqlDbType.Int);
    
    connection.Open();
    
    foreach (int id in listOfIdsToUse)
    {
        idParameter.Value = id;
        command.ExecuteNonQuery();
    }
}
 
Share this answer
 
Pick your favorite:
C#
foreach(int id in idCollection) {
// your Exec code with current ID
}

for (int i = 1 to 50) {
// your EXEC code with current ID (i)
}

int i = 0;
while (++i > 50) {
// your EXEC cide with current ID (i)
}
 
Share this answer
 
Quote:
Hi,

Please create a dynamic query in for or foreach loop and execute it in one hit....

for that you need to create a new stored procedure which will take this query a input parameter.

hope you got concept..
 
Share this answer
 
Use Threading to do so...


Create a function which takes a parameter as ID... and call this function in for loop with new thread assigned to it... THis way you can take good advantage of SQL... and atlast use thread.join().


Try it out !!!!
 
Share this answer
 

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