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
 Get sum value

Author  Topic 

pentahari
Starting Member

26 Posts

Posted - 2008-09-06 : 04:14:10
How to get the sum value for the nothing record

Table1:
date amount
1/1/2008 1000
1/3/2008 2000
1/5/2008 3000

My query is:
select amount from table1 where month(date)='1'

return values:
1/1/2008 1000
1/3/2008 2000
1/5/2008 3000

but i want this:
1/1/2008 1000
1/2/2008 0.00
1/3/2008 2000
1/4/2008 0.00
1/5/2008 3000
1/6/2008 0.00..

don't use front end because this query used as sub query.

Thanks Advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-06 : 04:43:15
use the F_TABLE_DATE to left join to your table

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519&SearchTerms=F_TABLE_DATE



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-06 : 23:26:10
or:-

select dateadd(d,v.number,m.start),coalesce(t1.amount.0)
from
(
select min(date) as start,max(date) as end
from table1 where month(date)='1')m
cross join master..spt_values v
left join table1 t1
on t1.date=dateadd(d,v.number,m.start)
where v.type='p'
and dateadd(d,v.number,m.start) <=m.end
Go to Top of Page
   

- Advertisement -