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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update Help

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 type

The condition is

IF SED is NULL then update INV with value of corresponding CURR
IF 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
Go to Top of Page

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

Go to Top of Page

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]
Go to Top of Page

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 :(
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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]
Go to Top of Page

Gigi
Starting Member

23 Posts

Posted - 2009-04-02 : 12:04:11
Vijayisonly,
Your solution displayed the same result

sakets_2000,
Your solution worked.

all, thank you for your help and the time and effort put in...truly appreciated.
Go to Top of Page
   

- Advertisement -