I have to load data into to Table (sample script for the table)
USE DevSamples GO IF EXISTS (SELECT * FROM sys.objects WHERE name = 'SSIS') DROP TABLE dbo.SSIS GO CREATE TABLE dbo.SSIS ( Id bigint NOT NULL IDENTITY, SSISCode bigint NOT NULL DEFAULT (8000) , ProcCode bigint DEFAULT (1), Value char(392) NOT NULL DEFAULT ('just stuff') ) ALTER TABLE dbo.SSIS ADD CONSTRAINT [SSIS_PK] PRIMARY KEY CLUSTERED ([Id] ASC) ALTER TABLE dbo.SSIS WITH CHECK ADD CONSTRAINT [FK_SSISCode_ProcCode] FOREIGN KEY([ProcCode]) REFERENCES dbo.SSIS([Id]) ALTER TABLE dbo.SSIS CHECK CONSTRAINT [FK_SSISCode_ProcCode] CREATE INDEX ix_SSIS ON dbo.SSIS (ID) SET NOCOUNT ON GO INSERT INTO dbo.SSIS DEFAULT VALUES GO 10 SET NOCOUNT OFF GO -- Just to have a few different values UPDATE dbo.SSIS SET SSISCode = (SSISCode - id) UPDATE dbo.SSIS SET ProcCode =8 WHERE ID > 5 UPDATE dbo.SSIS SET ProcCode =2 WHERE ID < 4 Select * from dbo.SSIS
FK Column ProcCode references ID column of the same table. I am trying to load the data from a Excel source. Excel data looks like this..
SSISCode, ProcCode, Value
-----------------------------
7999,7998,'just stuff'
7998,7998,'just stuff'
7997,7998,'just stuff
1. ProcCode will be resolved via a Lookup with SSISCode and insert ID value.
--When the table is empty how can I know the value of ID column for first time load?
2. I can initially load NULL to ProcCode and then update the value but for this I need
to have a staging table. Is there any better way to resolve the issue without a staging table?
Thank you for answerign my question.