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 |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2009-02-16 : 22:58:49
|
| //Is it possible to make storedprocedure like ://tbl structure :tbl1(id,col1,col2,...) tbl2(id,col1,...,chkcol)// select id,col1,col2... from tbl1,one of the rows already in tbl2{just change tbl2.chkcol=1},otherwise insert required fields of that row into tbl2thanks. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-16 : 23:15:29
|
| [code]CREATE PROC [dbo].[samplesp]( @ID INT)ASSET NOCOUNT ONBEGIN if EXISTS (select * from tbl2 WHERE id = @id) BEGIN UPDATE Tbl2 SET chkcol2 = 1 WHERE id = @id END ELSE BEGIN INSERT INTO tbl2 ( id,col1,co2,........ ) SELECT id,col1,col2,....... from tbl1 ENdENDSET NOCOUNT OFF[/code] |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-16 : 23:17:03
|
| declare @cnt intselect @cnt = Count(1) from tbl1 where id = @id and col1 = @col1------------update tbl1set chkcol = 1where id = @id and col1 = @col1 AND @cnt <> 0 ----------insert into tbl1columnsselect input parameterswhere @cnt = 0 |
 |
|
|
|
|
|
|
|