Reputation: 3515
I have two tables in a database on an SQL Server 2008 R2 server.
Table1:
Id, Value, Date
Table2:
Id, Value, Date
I am working on a ASP.Net MVC 4 project that utilizes Linq to SQL for database operations. I need to build a SQL command for db.ExecuteCommand(). No database Procedure or Function needed.
The SQL command should get {Value} and {Date} from Table1 depending on the "Id" entered by the user from the View. Then update {Value} and {Date} from all matching rows in Table2 where Tabl2.{Id} = {Id} of user input.
Is ExecuteCommand able to handle complex SQL command like this? How to build the command then? Thanks!
Upvotes: 0
Views: 613
Reputation: 8584
Do you mean something like this?
db.ExecuteCommand("UPDATE table2 SET value = (SELECT value from table1 WHERE ID = {0})", userEnteredId);
Upvotes: 1