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 |
|
Gigi
Starting Member
23 Posts |
Posted - 2009-04-02 : 11:20:39
|
| I want to update data in a colum. I have a column with no data in it called INV. I want to update it based on data in two other columns called SED and CURR. All three columns are of varchar data typeThe condition is IF SED is NULL then update INV with value of corresponding CURRIF SED is not null then update INV with 'SED=' + corresping value of SED |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-04-02 : 11:23:30
|
| UPDATE <urtable>SET INV = CASE SED WHEN NULL THEN CURR ELSE 'SED=' + SED END |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-04-02 : 11:23:33
|
UPDATE myTable SET INV=CASE WHEN SED IS NULL THEN CURR ELSE 'SED=' + SED END |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-02 : 11:23:50
|
| [code]update table set INV=ISNULL('SED='+SED,CURR)[/code] |
 |
|
|
Gigi
Starting Member
23 Posts |
Posted - 2009-04-02 : 11:39:05
|
| Vijayisonly, robvolk, sakets_2000, I tired the solutions that all you guys sent me and all three queries are giving me the same result and that is ....if SED is NUll then INV should get populated with the value in Curr but thats not happening....its getting populated with SED= the other condition works file and INV is being populated with 'SED='+SED where SED is not null.....and this is where I was stuck before I posted my question :( |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-02 : 11:48:53
|
| then SED must not be NULL. It must be a string of spaces. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-04-02 : 11:50:16
|
| That means..its not NULL..but sn empty string...try thi..UPDATE <urtable>SET INV = CASE NULLIF(SED,'') WHEN NULL THEN CURR ELSE 'SED=' + SED END |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-02 : 11:50:26
|
| [code]UPDATE myTable SET INV=CASE WHEN SED IS NULL OR SED='' THEN CURR ELSE 'SED=' + SED END[/code] |
 |
|
|
Gigi
Starting Member
23 Posts |
Posted - 2009-04-02 : 12:04:11
|
| Vijayisonly, Your solution displayed the same resultsakets_2000, Your solution worked.all, thank you for your help and the time and effort put in...truly appreciated. |
 |
|
|
|
|
|