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 2000 Forums
 SQL Server Development (2000)
 Table update

Author  Topic 

mksnyder
Starting Member

1 Post

Posted - 2005-10-25 : 17:32:32
Hi guys (and girls)...

I am using a table to provide extended data for our Item Master file.

To keep this simple, the Item Master table has an item number column, and then other columns that contain description, cost info, pricing, etc...

My table ALSO has the item number, and then the other columns we need for item specific information.

I want to INSERT a row into my table that copies the Item number, from the Item Master table only if the number doesn't exist in my table, and also inserts the current date into a DateAdded column.

It seems like it should be pretty straightforward...

Thank you in advance for any assistance...

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-10-25 : 18:04:40
I think this should do it. Try just the select part first to make sure it's what you want. You can also add whatever columns you want to both insert and select column lists.

insert myTable
(itemNumber
,dateAdded)

select im.itemNumber
,getdate() as dateAdded
from itemMaster im
left join myTable mt
on mt.itemNumber = im.itemNumber
where my.itemNumber is null


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -