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.
| Author |
Topic |
|
rbharatha
Starting Member
29 Posts |
Posted - 2005-11-24 : 04:34:19
|
| Hi All..I got 3 tables..tbl1, tbl2, tbl3I want to insert into tbl4 with the primary key ID's of (tbl1, tbl2, tbl3) and other valuesbased on the where condition that tbl3.name is equal to some parameter @name...If @name is not there in tbl3 then it should insert the record first into tbl3 and pass the value of scope_identity to the tbl4 insert sql.for ex:- If exists (select name tbl3 where name = @name) insert into tbl4 (id1, id2, id3, datetimestamp) values (@tbl1.id, @tbl2.id, tbl3.id, getdate())else step1 insert into tbl3 (name) values (@name) step2 insert into tbl4 (id1, id2, id3, datetimestamp) values (@tbl1.id, @tbl2.id, scope_identity(), getdate()) |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-11-24 : 04:39:12
|
| can you post your table structure ?-----------------[KH] |
 |
|
|
rbharatha
Starting Member
29 Posts |
Posted - 2005-11-24 : 04:45:30
|
| Hi Khtan... as requested here is the table structure of the tables...tbl1columns datatypecontactid int identity (1,1) not null,name varchar(50) null,createdby varchar(50) null,createddate datetime default getdate()tbl1columns datatypesuggestedid int identity (1,1) not null,name varchar(50) null,createdby varchar(50) null,createddate datetime default getdate()tbl1columns datatypenamematchid int identity (1,1) not null,name varchar(50) null,createdby varchar(50) null,createddate datetime default getdate()tbl4columns datatypeid int identity (1,1) not null,contactid intsuggestedid intnamematchid intcode varchar(50) null,office varchar(50) null,createdby varchar(50) null,createddate datetime default getdate() |
 |
|
|
|
|
|
|
|