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 2008 Forums
 Transact-SQL (2008)
 Adding a new amount to a YTD total

Author  Topic 

insideMyCity
Starting Member

2 Posts

Posted - 2012-06-05 : 15:04:17
I am trying to update a Numeric Year-To-Date total in Table 1 with additional numberic results from Table 2.

Each table consists of only one row each and are more for statistical placeholders for a website.

I am using this Commend Set:

UPDATE TABLE1 SET YTDTOTAL = (YTDTOTAL + NEWUPDATE) FROM TABLE1, TABLE2

My results continue to be a Null value when in Table1 the value is Null and NewUpdate in Table2 is 5.

I am sure if I was not sick with the stomach flu this would be easy but...

Scott

X002548
Not Just a Number

15586 Posts

Posted - 2012-06-05 : 15:51:32
UPDATE T1 SET YTDTOTAL = COALESCE(YTDTOTAL,0) + COALESCE(NEWUPDATE,0)
FROM TABLE1 T1 INNER JOIN TABLE2 T2 ON...??????
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-05 : 16:19:45
updating with CROSS JOIN? whats the purpose of that? dont you have a relationship between two tables?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -