codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

Updating table without replacing values that already exist in the original table with null values from the temporary table


By : , Category : sql

Use a condition in your WHERE clause to ignore NULL values

UPDATE stu
SET [studentname] = tmp.[studentname]
  , [studentclass] = tmp.[studentclass]

FROM [StudentDatabase].[dbo].[student] stu
INNER JOIN [StudentDatabase].[dbo].[student_temp] tmp  
    ON stu.[idstudent] = tmp.[idstudent]
WHERE tmp.[studentname] IS NOT NULL
ReLated :

Simply set the value of the property you want to make null, and save the changes:

var myRecord = dbContext.MyTable.First(...);
myRecord.MyColumn = null;
dbContext.SaveChanges();

Of course, the data type of the property must be nullable -- e.g. Nullable<int> rather than int.

If you want to delete the entire record, use the Remove method provided by the collection:

var myRecord = dbContext.MyTable.First(...);
dbContext.MyTable.Remove(myRecord);
dbContext.SaveChanges();
UPDATE TableName
SET Active = 0
WHERE NULLIF(?,Field1) IS NULL
  AND NULLIF(?,Field2) IS NULL
  AND NULLIF(?,Field3) IS NULL
  AND NULLIF(?,Field4) IS NULL
  AND NULLIF(?,Field5) IS NULL

The operator for NULL comparisons in SQL is IS and not = (similarly IS NOT instead of <> for inequality).

Change your queries to use WHERE column IS NULL instead of WHERE column = NULL.

You need to do this with a trigger. Example trigger:

create trigger schema.trigger_name
    before update of last_name
    on tablename
    for each row
begin
    if :old.last_name is not null then
        raise_application_error (-20100, 'Last name already has a value');
    end if;
end;
/

But this will stop any process that is running by raising a plsql error.

Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .