开发者

I need an SQL Query to compare Table1.field1 with Table2.field4, cut paste Table2.FoundRow results to Table3

开发者 https://www.devze.com 2023-03-19 09:37 出处:网络
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.Mon

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";
0

精彩评论

暂无评论...
验证码 换一张
取 消