Working on a project using sqlServer 2008.
EDIT for clarification : table 1 contains 1 field that has to be matched to Table2.field6 , if theres a match that row needs to be updated with DateTime.Month
string compareVals = 开发者_JAVA技巧"SELECT * FROM Table2 WHERE Table1.Field1 = Table2.Field4 and change table2.field6 to"+ DateTime.Month.ToString();
string CompareVals =
"UPDATE t2
SET field6 = month(getdate())
FROM Table2 t2
JOIN Table1 t1
ON t1.Field1 = t2.Field4"
I guess you want to update Table2.Field6
; so your query will look like this.
string CompareVals =
@"update Table2
set Table2.field6 = '" + DateTime.Month.ToString() + '" +
@" from Table1.field1
where Table2.Field4 = Table1.Field1";
精彩评论