In sql server 2008, i have a store procedure which has insert statement , now i want to insert multiple records at a time into table via EXEC.

MY Store Procedure:

insert into tblUser(fullname, email, loginID, password, DOB, question, answers,doc,roleid)
    values (@fullname,@email,@loginID,HASHBYTES('sha512',@password),@dob,@question, @answers, GETDATE(),@roleid )

Now how to insert multiple records via EXEC

exec dbo.appReg_sp 'Hunain','smile','fdsaf','password','1999-12-1','asas','sasa',1      ; now what next ?

Recommended Answers

All 7 Replies

call exec multile times

ok but any other alternative ?

urtivedi, thanks but it isn't a good practice and my store procedure has some other requirements so it doesn't suit that . Thanks anyway
any body else plz ?

but what do u mean by multiple insert then,

@utrivedi: sorry my mistake, INSERT statement in Store Procedure wa swrong now i modified it , look at this

**insert into tblAcademicRecord(educationlevel, examname,institution,passingyear,obtainedmarks,totalmarks,grade, percentage, remarks, userid)
    values(@educlvl, @examname, @institution, @Passingyr, @obtainedmarks, @totalmarks, @grade, @percentage, @remarks, @userid), (@educlvl, @examname, @institution, @Passingyr, @obtainedmarks, @totalmarks, @grade, @percentage, @remarks, @userid)**

now tell me that how to pass values to it via EXEC bcz i has now 2 rows of arguments ....have a look

urtivedi, thanks but it isn't a good practice and my store procedure has some other requirements so it doesn't suit that . Thanks anyway
any body else plz ?

How you say that it is not a good practise to call procedure twice or n number of times.

inserting 1 row is one operation and inserting 2 rows are 2 distinct operation

in your code if you have n number of rows to insert you have to call your procedure n number of times.

If you feel stored procedure another requirement in your case, you can direct write insert statement in your code itself in loop. this is normal practise. or you can 2 separte stored proceudre one for inserting record only another for your other requirement.

@utrivedi : well that was my mistake . now have u seen my recent post ?
new query which i mentioned after modification ? any solution for that ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.