SQL Server - Updating multi rows in data table with Update Stored procedure

Asked By bhanupratap singh on 01-Sep-14 10:40 AM
My requirement is to update multiple row in a table with update stored procedure.
my Table record is like below
Table name is MfHead

DespatchedFrom   ChallanNo         cnmtNo    CnmtDate    Package
Delhi 1212 101 01/01/2013        5
Delhi 1212 102 02/01/2013 8
Delhi 1212 103 02/01/2013 8
Delhi 1212 104 05/01/2013 5
I need to update cnmtno    cnmtdate   and package  all four rows

where despatchedfrom='Delhi' and ChallanNo=1212

I'm updating through gridivew

Irbaz Hashmi replied to bhanupratap singh on 01-Feb-13 01:17 PM
You must have some unique field for each row or a set of unique fields to update row other wise all 4 columns will be update on you where criteria.
You can add column with RecordID auoincrement and then update on behalf of RecordID 
bhanupratap singh replied to Irbaz Hashmi on 02-Feb-13 12:40 AM
Thanks for reply
Ok If I give auto increment row id then how will be the query written in stored procedure
Pls give sum hints

Irbaz Hashmi replied to Irbaz Hashmi on 02-Feb-13 03:49 AM
This is the basic how to write Stored Procedure


@ID int,
@cnmtno int,
@cnmtdate datetime,
@package int


SET cnmtno = @cnmtno,
cnmtdate = @cnmtdate,
package = @package
WHERE despatchedfrom='Delhi' and ChallanNo=1212 and IDCOL = @ID