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 |
|
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? |
 |
|
|
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. |
 |
|
|
arorarahul.0688
Posting Yak Master
125 Posts |
Posted - 2007-11-07 : 05:04:53
|
| use the COALESCE function to fetch the yeserday value likeselect COALESCE(yesterday_entry ,0) from table namein this case if the value of yesterday_entry is null it wll consider it as 0read about Coalesce function it will clear the sceneRahul Arora MCA 07 BatchNCCE Israna, PanipatHRY, INDIA######################IMPOSSIBLE = I+M+POSSIBLE |
 |
|
|
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 |
 |
|
|
|
|
|
|
|