Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Inserting Distinct Rows from One Table Into Another

$
0
0

I have a really basic question and I've seen the answer on the forum but it isn't working for me. I have one table that has a lot of data and I want to copy the Distinct value of one column and populate a column in another table with that value. This is the PK for the second table.

So the select distinct works fine and returns valid rows of data and only valid rows of data, but when I combine it with the INSERT I get the following message:

Msg 515, Level 16, State 2, Line 3
Cannot insert the value NULL into column 'Description', table 'Inventory.dbo.DatasetDescription'; column does not allow nulls. INSERT fails.

Here is the code:

USE [Inventory]
GO

INSERT INTO [dbo].[DatasetDescription]
           ([DatasetName]
          )
     SELECT DISTINCT [DatasetName] FROM [dbo].[SMF Analysis Meta Database]

I'm at a loss as I've seen several examples of this in the forum. I've checked and I don't have any null DatasetNames in my source data, so I don't understand what the problem is, or more likely what I'm doing wrong.

Thanks in advance.

Rodney


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>