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 |
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-08-02 : 07:28:12
|
| Thank you in advance for your help.My issue is as follows:For all jobid's I am looking to identify the difference between rev and ta. However in the underlying view_f_rev when there are zero values, instead of zeros appearing I get blank rows. So in these instances, the calculation below of a.revenue - b.ta yields no results.How do I resolve this? Many thanksDECLARE @PERIOD INTset @period = '2';with cterev as(select jobid,sum(REV) as revenue from View_F_REV where TreeYear = '2011' AND YEAR = '2011' AND PeriodID <= @PERIOD and BUKey in (select BUKey from D_BusinessUnits where TerritoryName = 'UK' and SBLID = 'MKG' and year = '2011') AND LK = '1' group by JobID),cteta as (select jobid,sum(rev) as ta from View_F_REV where TreeYear = '2011' AND YEAR = '2011' AND PeriodID <= @PERIOD and BUKey in (select BUKey from D_BusinessUnits where TerritoryName = 'UK' and SBLID = 'MKG' and Year = '2011') AND LK = '10' group by JobID)select a.revenue,b.ta,(a.revenue - b.ta),* from cterev a inner join cteta bon a.JobID = b.JobIDwhere a.JobID = '100108470102' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-02 : 07:38:37
|
| sum will never return blank. whats the datatype of rev in tables?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-08-02 : 07:44:32
|
| bigint |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-02 : 07:50:47
|
| it will be never return blank unless you cast it to varchar.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-08-02 : 08:02:32
|
| Sorry, when i say blank rows, i mean no rows |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-02 : 11:50:20
|
| that means you dont have records from both the ctes for jobid='100108470102'check if it satisfies both the cte conditions.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|