Anda dapat membuat tipe tabel dan meneruskan nilainya, seperti itu:
CREATE TYPE Suite_Lease AS TABLE
(
suite_id varchar(15) NOT NULL,
lease_id varchar(15) NOT NULL
)
GO
CREATE PROC DoUpdate
@Params Suite_Lease READONLY,
@uplift varchar(15),
@code varchar(15)
AS
update property.lease_period set
scca_uplift = @uplift,
scca_notes_code = @code
from property.lease_period tab
JOIN @params filt
on tab.suite_id=filt.suite_id AND tab.lease_id=filt.lease_id
Ini akan menjaga Cache Prosedur . Anda kering dan bersih, sebagai gantinya jika Anda menggunakan beberapa klausa "besar" di mana
Cara meneruskan parameter tabel ke prosedur tersimpan (c#):
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("suite_id", typeof (string)) {AllowDBNull = false, MaxLength = 15});
dt.Columns.Add(new DataColumn("lease_id", typeof (string)) {AllowDBNull = false, MaxLength = 15});
dt.Rows.Add("CCBG08", "205059");
... add more rows for match
using (var c = new SqlConnection("ConnectionString"))
{
c.Open();
using(var sc = c.CreateCommand())
{
sc.CommandText = "DoUpdate";
sc.CommandType = CommandType.StoredProcedure;
sc.Parameters.AddWithValue("@uplift", "110");
sc.Parameters.AddWithValue("@code", "21006");
sc.Parameters.Add(new SqlParameter("@Params", SqlDbType.Structured) { TypeName = null, Value = dt });
sc.ExecuteNonQuery();
}
}