Update statement for SQl Server is not working




 I have a SQL Server 2005. I have two tables. Table1 is the old table and table2 is the updated table. I am trying to update table1 with table2 data but my update code is wrong. What I have in table1 is just Firstname , Lastname, Email, accesslevel. Table2 has the updated First, Last and Email. I just want to update the Firstname, Lastname and Email without loosing the accesslevel in table1. Also the tables have userid's in them also. I was trying to update table1 with table2 data depending on the userid. Here is my code.  

  


```
UPDATE [Hot].[dbo].[Table1] SET [Firstname], [Lastname], [Email] = 
Table1.userid
FROM Table2
WHERE [Hot].[dbo].[Table2].userid = Table2.userid
```
Try this:  


```
UPDATE table1
SET
    table1.firstname = table2.firstname,
    table1.lastname = table2.lastname,
    table1.email = table2.email
FROM
    table1 JOIN table2
ON
    table1.userid=table2.userid
```
You can provide an optional parameter to the scaffolding command to update only the table you target.



```
Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DirectoryNameOfYourModels -Tables employee -f

```

If you are using .net core cli then use.



```
dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o DirectoryNameOfYourModels -t employee -f

``` Hi  

This is simple. First check whether you are able to connect Sql Server through SSMS or not.If you are able to connect through SSMS, then there may be a problem in connection string. If you are not able to connect through SSMS, then you had some problem with SQL Environment. Should be able to do something like this:


UPDATE table\_name  

SET new\_column = (calculated value)  

WHERE new\_column is NULL Yes  

You would need to run the ‘LABEL ON’ SQL Statement.  

Here is a sample of code that changed the column heading for field JOBID from ‘Job ID’ to ‘NEW COLUMN HEADING’  

File is CD053DB In library Charlieb


LABEL ON COLUMN CHARLIEB/CD053DB (JOBID IS ‘NEW COLUMN HEADING’) Lets say you want to send a table with a single column of GUIDs.


First we need to create a structure using [SqlMetaData](https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.server.sqlmetadata(v=vs.110).aspx) which represents the schema of the table (columns).



```
var tableSchema = new List<SqlMetaData>(1)
{
  new SqlMetaData("Id", SqlDbType.UniqueIdentifier)
}.ToArray();

```

Next you create a list of records that match the schema using [SqlDataRecord](https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.server.sqldatarecord(v=vs.110).aspx).



```
var tableRow = new SqlDataRecord(tableSchema);
tableRow.SetGuid(0, Guid.NewGuid());
var table = new List<SqlDataRecord>(1)
{
  tableRow
};

```

Then create the [SqlParameter](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter(v=vs.110).aspx):



```
var parameter = new SqlParameter();
parameter.SqlDbType = SqlDbType.Structured;
parameter.ParameterName = "@UserIds";
parameter.Value = table;

var parameters = new SqlParameter[1]
{
  parameter
};

```

Then simply call the stored procedure by using the [Database.SqlQuery](https://msdn.microsoft.com/en-us/library/gg696545(v=vs.113).aspx).



```
IEnumerable<ReturnType> result;
using (var myContext = new DbContext())
{
  result = myContext.Database.SqlQuery<User>("GetUsers", parameters)
    .ToList();         // calls the stored procedure
    // ToListAsync();  // Async
{

```

In SQL Server, create your User-Defined Table Type (I suffix them with TTV, Table Typed Value):



```
CREATE TYPE [dbo].[UniqueidentifiersTTV] AS TABLE(
  [Id] [uniqueidentifier] NOT NULL
)
GO

```

Then specify the type as a parameter (don't forget, Table Type Values have to be readonly!):



```
CREATE PROCEDURE [dbo].[GetUsers] (
  @UserIds [UniqueidentifiersTTV] READONLY
) AS
BEGIN
  SET NOCOUNT ON

  SELECT u.* -- Just an example :P
  FROM [dbo].[Users] u
  INNER JOIN @UserIds ids On u.Id = ids.Id
END

``` Here is a link to assist you.


<https://technet.microsoft.com/en-us/library/ms178078(v=sql.105).aspx>


If you had done a web search with the question you entered here, you would have found multiple sites that give you the instructions you might be able to use synchronize. if you have more than 2 tables, you will need to use it multiple times. let table = base.gettable("table 1")

let record = await input.recordasync("record", table)

await table.updaterecordasync(record.id, {

"single select": null

}) Change this line of code (sql query) into:



```
OleDbCommand cmd = new OleDbCommand(Stirng.Format("INSERT INTO CHILDREN2 (Emp_ID , Child_Name, Age) VALUES ({0}, {1}, {2})", Convert.ToInt32(CaptionText.Text),txtName.Text, txtAge), clsData.con);
```

Do you have a WHERE clause too? I removed it from your query, becasue it didnt belonge on that place where you put it.  

If you will use a Where clause then create an sql query this was:



```
"INSERT INTO TableName (Field1, Field2) VALUES (@paramField1, @paramField2) WHERE Field3 = @paramField3"
```

where params are parameters passed to the fields, and WHERE is a conditional clause, and has to be stated on the end (after specifying parameters). SQL Express doesn’t support maintenance plans so the Tools don’t include those options. To use Maintenance plans you’ll need to get the Workgroup or above edition of SQL Server 2008.