As per the comments, I'm going to assume you're getting mixed up between update and insert.
USE [DB_A] ;
UPDATE dbo.address
SET City = 'test',
State = 'ing'
WHERE City IS NULL ;
And
USE [DB_A] ;
UPDATE dbo.address
SET City = NULL,
State = NULL
WHERE City = 'test' ;
I think you're there otherwise :-)
Answer from kezsto on Stack ExchangeVideos
When you use a column with NOT NULL then it's not possible to add NULL to the column.
I guess you have other columns as well, like:
Create TABLE Products
(
[ProdID] [int] IDENTITY(1,1) NOT NULL,
[Col2] int NULL,
[Col3] int NOT NULL,
[Col4] int NULL
)
When you want to insert a record to this table dont mention the [ProdID] column, it will be filled automaticly because its a identity.
Example:
INSERT INTO Products ([Col2],[Col3],[Col4]) VALUES (1,2,NULL)
Looks like column mapping issue in your ssis package.
It might have mapped to the column from other table or select which has null values and also check identity insert enabled or not.
If a value is NULL, then adding it to a string will produce a NULL. This allows us to add the quotes in the ISNULL check and just produce NULL in the true value of the check, producing the correct syntax for nulls or not nulls as necessary.
select 'Insert into Organizations(Name, IndustryId, ContactPerson, Email, Website, LocationId, ContactNumber, Mobilenumber) values(' +
IsNull(''''+Nameofthecompany+'''', 'NULL') + ', ' +
Isnull(''''+IndustryType+'''', 'NULL') + ', ' +
Isnull(''''+Nameofthepersonresponsibleforrecruitment+'''', 'NULL') + ', ' +
Isnull(''''+EmailId+'''', 'NULL') + ', ' +
Isnull(''''+websiteaddress+'''', 'NULL') + ', ' +
Isnull(''''+Location+'''', 'NULL') + ', ' +
Isnull(PhoneNumber, 'NULL') + ', ' +
Isnull(MobileNumber, 'NULL') + ')'
from Organization
If you want to use NULL (as a literal - not a string) for your NULL values, then the creation of the INSERT statement gets a lot more complicated; if the value is NULL, then you need to add the literal NULL without a leading and trailing '.
For each column where you want to do this, you'll need to use a CASE statement - something like this:
select 'INSERT INTO Organizations(.....) ' +
'VALUES(' +
CASE
WHEN NameOfTheCompany IS NOT NULL
THEN '''' + NameOfTheCompany + ''', '
ELSE 'NULL, '
END +
CASE
WHEN IndustryType IS NOT NULL
THEN '''' + IndustryType + ''', '
ELSE 'NULL, '
END +
..... and so on ......
+ ')'
... and so on, for each column you need this CASE statement ....