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 |
|
PatDeV
Posting Yak Master
197 Posts |
Posted - 2009-01-03 : 14:55:03
|
| Hi all,I want to do is insert data if company is not exist and if company, date and id exist then update the rest of the data!! How can i do that. what would be best approach for me! |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-03 : 15:05:45
|
| There are lots of post regarding this issue. Please search for it in Searc tab. |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-04 : 23:33:29
|
| IF NOT EXISTS(SELECT 1 FROM urtable WHERE companyid = @companyid)BEGIN INSERT StatementENDELSE BEGIN UPDATE StatementEND@companyid is i/p parameterJai Krishna |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-04 : 23:35:49
|
| Hi U can also try thisDECLARE @cnt INTSELECT @cnt = COUNT(1) FROM urtable WHERE companyid = @companyidINSERT INTO urtableSELECT @companyid,,,,,,,,,,,,WHERE @cnt = 0UPDATE urtable SET companyid = @companyid,,,,,,,,,,,WHERE @cnt <> 0Jai Krishna |
 |
|
|
|
|
|
|
|