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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Update statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-24 : 09:19:11
Terry Beebe writes "I would like to update a single table with the following criteria.

Lets call this table earnded; the columns are numerous; however i want to update only one column called ytdrptearnsubjded.

The tricky part is this:

I only want to update the column ytdreptsubjearnded if the earndedid = 'azd1 and calyr = 2001(rows); AND I ONLY want to update the ytdreptsubjearnded with the value that is currently in ytdreptsubjearnded but the earndedid (row) is = fed1 and the calyr = '2001';.

Therefore, update the earnded table column ytdreptsubjearnded if: the earndedid = azd1 and replace it with the ytdearndedsubjded IF the earndedid = fed1.


I HAVE TRIED THE FOLLOWING TO NO AVAIL?.
begin transaction
update earnded set YtdRptEarnSubjDed = case(when EARNDEDID = 'AZD1' AND CALYR = '2001'
then YtdRptEarnSubjDed when
EARNDEDID = 'FED1' AND CALYR = '2001'

begin transaction
update earnded set YtdRptEarnSubjDed = (SELECT YtdRptEarnSubjDed FROM EARNDED WHERE
EARNDEDID = 'FED1' AND CALYR = '2001')
WHERE EARNDEDID ='AZD1'

I would be forever grateful... for any assistance. Unfortunetly, time is of the essense..

Thanks"

Nazim
A custom title

1408 Posts

Posted - 2002-01-24 : 10:08:05
update e set e.YtdRptEarnSubjDed = case EARNDEDID when 'AZD1' then
(case CALYR = '2001' then e1.YtdRptEarnSubjDed else e.YtdRptEarnSubjDed end) else e.YtdRptEarnSubjDed end
from e left join (select * from earned where
EARNDEDID = 'FED1' AND CALYR = '2001') e1
on e.primarykey=e1.primarykey


HTH


--------------------------------------------------------------
Dont Tell God how big your Problem is , Tell the Problem how Big your God is



Edited by - Nazim on 01/24/2002 10:16:07
Go to Top of Page
   

- Advertisement -