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
 General SQL Server Forums
 New to SQL Server Programming
 Insert into a joined table if exists in lookup tbl

Author  Topic 

pwvailla
Starting Member

31 Posts

Posted - 2010-09-27 : 23:09:35
table A
orderno
buscode
busunit
custname
engno

table b
orderno
buscode
busunit
custname
engno
engstart
engfinish

table c
orderno
projectno
project_name

table d
projectno
project_status

SQL problem:
Table A is used to update / insert records into table B provided the orderno exists in table c and the table D project_status = 'A' for an active project.

I know you will connect the tables A + B with orderno+buscode and tables A + C with orderno and table C + D by projectno.

Do you create a separate UPDATE routine and an INSERT? What would they look like with the JOINS?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-30 : 12:32:04
if you're using SQL 2008 you can use MERGE. else you need separate UPDATE and INSERT. UPDATE will have INNER JOIN between A and B as its for existing records and INSERT will have LEFT JOIN and condition check b.field IS NULL to identify new records

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -