Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Update logic in Warehouse ...

Author  Topic 

frank.svs
Constraint Violating Yak Guru

368 Posts

Posted - 2008-02-05 : 08:42:21

Hi,

I am facing a small problem while updating the warehouse using SSIS package.

Here is an sample scenario.
I have a staging table T1 with some important columns as stateid,ename etc ..
and target table as Trg with only two columns stateid and statecnt.
The Rule is, each state will be sending an excel file which basically contains state and employees belonging to the state information.
For the first time when i execute the SSIS package, i need to load statetid and count_of_employees for that particular state.
say for example.

SELECT stateid,
count(ename)
from T1
where stateid = ?

For the next time if the same state information is received then we need to update the count to the existing record in the Dataware house rather than creating a brand new record once again.

I am little bit confused of implementig this logic.
Can anyone help me out in accomplishing this task.
What can done or what steps is involved in achiving the task.

Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-06 : 04:22:23
You may use a SQL Command task to achieve it. the logic will be like:-

UPDATE t
SET t.statecnt=t1.statecnt
FROM Trg t
INNER JOIN (SELECT stateid,
count(ename) as statecnt
from T1) t1
ON t1.stateid= t.stateid

INSERT into Trg
SELECT stateid,
count(ename) as statecnt
from T1 t1
LEFT OUTER JOIN Trg t
ON t.stateid=t1.stateid
WHERE t.stateid IS NULL
Go to Top of Page

Qualis
Posting Yak Master

145 Posts

Posted - 2008-02-07 : 13:31:50
Don't forget your Group By stateid on your Selects. ;)
Go to Top of Page
   

- Advertisement -