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 2008 Forums
 Transact-SQL (2008)
 merge when no matched delete

Author  Topic 

sarahmfr
Posting Yak Master

214 Posts

Posted - 2012-01-23 : 10:58:46
Hi All,
I have a table that includes
sectioninstructor(sectionid , instructorid, instructorrole)
those are sections taught in various semesters
another table
Sectionsemesster(sectionid, semesterid ,etc)
table
Section(sectionid,sectionnumber,etc)
third table
instructor(instructorid,name,email etc)

I receive an xls spread sheet
sectionnumber,instructoremail,instructorrole,semesterid
the instructor can be removed i.e will not teach the section anymore

on merge I would like
when not matched source delete but I want to deal with only sections taught that in that particular semester or else it will delete all in the other semesters
i.e.
I want the target not to be the whole sectioninstructor table but only those where section are taught in a semester
i.e target is a view linking the section instructor table with section semester table and filtering only those taught in a particular semester.
Thanks


sarah

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-23 : 12:31:36
At first glance it appears that you have a bit of a schema issue. However, without the proper table structure and sample data it's hard to tell. Here are two links on how to prepare your sample data so that we can help you better:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go to Top of Page
   

- Advertisement -