This post is part of a series dedicated to database access. This is the stored procedure (SP) that deletes rows in the database.
DEL SP has the same parameters as the GET SP, with the restriction that the parameters have to belong to the affected datatable. With these parameters the DEL operation is more flexible because it can affect not only the row affected by the PK but other ones.
As usual, a code example:
DELETEFROM DI_EXP_DESTRUCCIO
WHERE
((@pPK_Destruccio ISNULL) OR (PK_Destruccio=@pPK_Destruccio)) AND
((@pFK_TAAD ISNULL) OR (DI_EXP_DESTRUCCIO.FK_TAAD = @pFK_TAAD))
AND ((@pFK_Estat ISNULL) OR (DI_EXP_DESTRUCCIO.FK_Estat = @pFK_Estat))
AND ((@pDataInici ISNULL) OR (DI_EXP_DESTRUCCIO.Data_Destruccio BETWEEN @pDataInici AND @pDataFi))
AND ((@pFK_Arxiu ISNULL) OR (DI_EXP_DESTRUCCIO.FK_Arxiu = @pFK_Arxiu))
#03/03/2014 16:06 Programming SQLServer Author: Alex Canalda