I have two tables in different databases on the same database server.
Both the databases have the same structure, but different data. Database1 (Test1) is the latest
this works wonders - no its turn to call this procedure form code with DataTable with schema exactly matching the custType create table customer ( id int identity(1,1) primary key, name varchar(50), cnt varchar(10) )
create type custType as table
(
ctId int,
ctName varchar(20)
)
insert into customer values('y1', 'c1')
insert into customer values('y2', 'c2')
insert into customer values('y3', 'c3')
insert into customer values('y4', 'c4')
insert into customer values('y5', 'c5')
declare @ct as custType
insert @ct (ctid, ctName) values(3, 'y33'), (4, 'y44')
exec multiUpdate @ct
create Proc multiUpdate (@ct custType readonly) as begin
update customer set Name = t.ctName from @ct t where t.ctId = customer.id
end
public DataTable UpdateLevels(DataTable dt)
{
DataTable dtRet = new DataTable();
using (SqlConnection con = new SqlConnection(datalayer.bimCS))
{
SqlCommand command = new SqlCommand();
command.CommandText = "UpdateLevels";
command.Parameters.Clear();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@ct", dt).SqlDbType = SqlDbType.Structured;
command.Connection = con;
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
{
dataAdapter.SelectCommand = command;
dataAdapter.Fill(dtRet);
}
}
}
UPDATE table1
SET column1 = (SELECT expression1
FROM table2
WHERE conditions)
[WHERE conditions];