Reputation: 3
Firstly, I have read through other posts on this page regarding similar issues but I cannot figure out where I am going wrong. I want to populate a column of [table1] with values from another column in [table2].
When I run,
insert into Staged.dbo.factSales(Date)
select SaleDate
from Staged.dbo.SaleDates
I get the following error
Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'SaleValue', table 'Staged.dbo.factSales'; column does not allow nulls. INSERT fails.
SaleValue
is the column in Staged.dbo.factSales
and design-wise, comes after 'Date' - SaleID, OrderID, ProductID, BranchID, EmployeeID, Date, SaleValue.
Does anyone have any idea where I am going wrong? Thanks in advance!
Marcin
Upvotes: 0
Views: 78
Reputation: 3
Fixed using
update Staged.dbo.factSales set Staged.dbo.factSales.Date = Staged.dbo.SaleDates.SaleDate from Staged.dbo.factSales inner join Staged.dbo.SaleDates on Staged.dbo.factSales.SaleID = Staged.dbo.SaleDates.SaleID
Upvotes: 0
Reputation: 81930
SalesValue does not allow nulls, so supply a zero.
Insert into Staged.dbo.factSales (Date,SaleValue)
Select SaleDate,0 from Staged.dbo.SaleDates
Upvotes: 1