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 |
|
callinnn
Starting Member
7 Posts |
Posted - 2007-05-22 : 01:15:32
|
| I have my table like thisCode Amount Debit Credit D 230 C 440 C 890 D 560I want to update amount in Debit if Code is DElse i want to update it into CreditHow can i establish thisPlease Help |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-22 : 01:23:12
|
| [code]Update Tableset Debit = case when Code = 'D' then Amount else 0 end,set Credit = case when Code = 'C' then Amount else 0 end[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2007-05-22 : 01:26:28
|
| update Table Set Debit = case Code when 'D' then Amount end,Credit = case Code when 'C' then Amount end |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-05-22 : 01:41:14
|
| Use a Computed column? Bit of a waste re-storing the same value, and you runt he risk that the UPDATE doesn't run, or the values get out of sync etc.Personally I would use a VIEW rather than a Computed column.Kristen |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-22 : 01:46:58
|
quote: Originally posted by harsh_athalye
Update Tableset Debit = case when Code = 'D' then Amount else 0 end,set Credit = case when Code = 'C' then Amount else 0 end Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
KH |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-22 : 01:49:51
|
| CnP syndrome!Thanks KH.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-22 : 02:36:09
|
quote: Originally posted by harsh_athalye CnP syndrome!Thanks KH.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
 KH |
 |
|
|
|
|
|