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 |
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2005-08-03 : 10:46:35
|
| How do I do thisI am doing an insert. One of the fields I pass in is a groupid. Depending on that ID, I need to update a one of 3 fields. if groupid = 1 then I need to update the a field, if groupid = 2 then I need to update the b field |
|
|
kapilarya
Yak Posting Veteran
86 Posts |
Posted - 2005-08-03 : 10:51:13
|
| write a insert trigger in which you can check the value of group id and accordingly run the update statementKapil Arya |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-03 : 10:52:03
|
| If groupid = 1 Update yourtable set a='somevalueelse if groupid = 2Update yourtable set b='somevalueMadhivananFailing to plan is Planning to fail |
 |
|
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2005-08-03 : 11:30:23
|
Well the only problem is I am updating 40 fieldsquote: Originally posted by madhivanan If groupid = 1 Update yourtable set a='somevalueelse if groupid = 2Update yourtable set b='somevalueMadhivananFailing to plan is Planning to fail
|
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-08-03 : 22:51:23
|
you said you were updating 3 fieldsquote: How do I do thisI am doing an insert. One of the fields I pass in is a groupid. Depending on that ID, I need to update a one of 3 fields. if groupid = 1 then I need to update the a field, if groupid = 2 then I need to update the b field
try the case statementupdate tableset field=case when criteria1 then value1when criteria2 then value2...endwhere....--edityour subject is insert, so why not just do this checking before inserting the record so you won't have to do the update? it works the same way minus the update transaction--------------------keeping it simple... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-04 : 01:05:27
|
| >>update tableset field=case when criteria1 then value1when criteria2 then value2Jen, this will work if the field to be updated is same but assigning different valuesHe wants to update different field according to conditionhelixpoint, can you explain more on what you are trying to do?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|