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
 Transact-SQL (2005)
 Insert question

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-10-01 : 09:07:12
I have two tables:

diary
-----

diarydate datetime,
description varchar(25),
clientno int


and

clients
-------

clientno int,
statusid int,
first_name varchar(25),
last_name varchar(25)

I want to insert a new record into the diary table for each entry of the clients table which has a statusdid of 20.

How can I do this please?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-01 : 09:46:47
insert into diary (columns)
select columns from clients as c
where statusid=20 and
not exists(select * from diary where clientno=c.clientno)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -