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
 Compare old data to new data

Author  Topic 

nschultz12
Starting Member

2 Posts

Posted - 2007-11-05 : 14:56:51
I'm trying to compare two dates of data for loan balances. For example, if I want to know what the balances for branches A,B, and C are, today vs. yesterday, I want a report that has two columns: today and yesterday. And 3 rows: branches A, B, and C. The report is accurate, only if the 3 Branches exist today and yesterday. What if Branch B, for example didn't exist yesterday? How do I compare something to nothing? I wouldn't want total loan balances to be misrepresented because a particular branch didn't exist at one point in time when the comparison is ran.

How do I go about this?

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-05 : 17:28:48
you would do a left join from this month to the table from last month so that all records present this month return a value, and anything not present in last month would like return NULL since there is nothing there. How likely is it that a branch didn't exist yesterday?
Go to Top of Page

nschultz12
Starting Member

2 Posts

Posted - 2007-11-05 : 18:52:43
Thanks for replying dataguru1971! I'll try what you said. I've been thinking on the lines of an outer join to Table A or Table B.

Where I work, branches aren't all "Brick and Mortar" We have phone centers, web, etc. Currently management is restructuring, therefore old branches no longer exist. Basically they want to split and rename branches. By doing so, we should make a profit. :)

In my world, simplicity is the essence of reliability.
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2007-11-07 : 05:04:53
use the COALESCE function to fetch the yeserday value like
select COALESCE(yesterday_entry ,0) from table name

in this case if the value of yesterday_entry is null it wll consider it as 0

read about Coalesce function it will clear the scene

Rahul Arora
MCA 07 Batch
NCCE Israna, Panipat
HRY, INDIA

######################
IMPOSSIBLE = I+M+POSSIBLE
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-11-07 : 05:52:39
"use the COALESCE function to fetch the yeserday value like"

No, this is a missing ROW not a COLUMN with a NULL value.

Kristen
Go to Top of Page
   

- Advertisement -