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)
 Conditional split based on conditions

Author  Topic 

lols
Posting Yak Master

174 Posts

Posted - 2007-09-23 : 05:09:42
Hi,

I have the following table in MsAccess


EmployeesA

empId integer,

empName varchar(60),

empAge integer,

empStatus char(1) - can be N,D or S - New, Deleted or Shifted


and the following in Sql2005

EmployeesB

Id smallint,

Name varchar(60),

Age int,

Status char(1) - Bydefault 'N'


I have written a Foreach File package that populates the sql server tables (EmployeesB) from Access(EmployeesA). However i want to check for a condition now.

If empStatus = N in EmployeesA, then insert a new record in EmployeesB

If empStatus = D in EmployeesA, then search for that field in the EmployeesB by passing empname and age and if found, mark the Status field in EmployeesB as 'D'

If empStatus = S in EmployeesA, then search for that field in the EmployeesB by passing empname and age and if found, mark the Status as 'S' in EmployeesB and insert a new row.

How do I do it for each table each row in EmployeesA using a foreach file loop?


Thanks,

lolsron

Kristen
Test

22859 Posts

Posted - 2007-09-23 : 05:49:57
This is basically the same question as you are asking here:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=89839

Folk here are likely to waste time duplicating answers because they are not aware of the other thread, so I think better to keep all the discussion over on the other thread pls

Kristen
Go to Top of Page

lols
Posting Yak Master

174 Posts

Posted - 2007-09-23 : 06:41:46
Kirsten,

How are the 2 posts the same? The first post asks about schema validations while this one is about conditional queries?

Yes the tables are the same but the queries are entirely different.

thanks.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-09-23 : 20:13:06
Why are you using a for each file? Sounds like you have a table in an access database that you are importing to sql server.

I suspect you are looking for a merge join to check for the existence of rows and a conditional on the result to control the execution.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

lols
Posting Yak Master

174 Posts

Posted - 2007-09-23 : 23:54:02
Hi nr,

thanks for your reply. I am using a foreach as there are multiple mdb in a folder which i am picking one by one and reading a table out of that.I want to check each row based on the condition mentioned in my previous post and then take an action accordingly.

thanks
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-24 : 02:14:10
"How are the 2 posts the same?"

The whole foreach discussion is now in two threads, together with how you get the data imported.
Go to Top of Page

lols
Posting Yak Master

174 Posts

Posted - 2007-09-24 : 06:30:23
I solved it..thanks for all the help :)
Go to Top of Page
   

- Advertisement -