Search code examples
sql-servernullablesuppress-warningsselect-into

Getting a non-NULL-able warning when using SELECT * INTO


When I execute the following proc, I get this warning:

Attempting to set a non-NULL-able column's value to NULL.

USE [DbTwo]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

alter proc [dbo].[TEST_warning_proc]
as 

IF OBJECT_ID('MySchema..vitals', 'U') IS NOT NULL DROP TABLE MySchema..vitals
IF OBJECT_ID('MySchema..order_list', 'U') IS NOT NULL DROP TABLE MySchema..order_list

select * into MySchema..vitals
from DbOne..vitals
where FacilityID in
 (select FacilityID from DbTwo..MySchemaFacilities)

select * into MySchema..order_list
from DbOne..order_list
where FacilityID in
 (select FacilityID from DbTwo..MySchemaFacilities)

How can this be possible since I'm doing a SELECT * INTO? Shouldn't that create a new table that exactly mirrors the original table?

I tried setting:

SET ANSI_WARNINGS OFF

but that didn't help.


Solution

  • I found the issue...

    When I was "sanitizing" my proc for posting here, I used the names

    from DbOne..vitals
    

    and

    from DbOne..order_list
    

    These two objects are actually views not tables. I tried running the original SELECT from the definition of the view and got:

    Null value is eliminated by an aggregate or other SET operation.

    Oops... My apologies.