Question : MSSQL query count te values of te outut from te subquerys

Hi,

On my query i use 3 subquerys. I like tot count this in te query but if 1 off te subquery's reteurn NULL te totaal count will be NULL.

Greatings Gerard
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
SELECT DISTINCT
                         (select cast(cast(sum(New_Durationorig)  as decimal(13,2)) / 60 as  
                           decimal                  (13,2)) * 95 FROM FilteredBB_urenregistratie 
                          where BB_werkzaamhedenName not like 'GENERIEK%'
                          AND datepart(month,bb_datum) = @TDate 
                          AND datepart(year,bb_datum)= @TYear
                          AND BB_ProjectIdName = @TProject
                          AND BB_Billable = 1
                          AND bb_momentvandedagname = 'Kantoortijden(08:30-17:30)') +
                          
                          (select cast(cast(sum(New_Durationorig)  as decimal(13,2)) / 60 as decimal(13,2)) * 143 FROM FilteredBB_urenregistratie 
                          where BB_werkzaamhedenName not like 'GENERIEK%'
                          AND datepart(month,bb_datum) = @TDate 
                          AND datepart(year,bb_datum)= @TYear
                          AND BB_ProjectIdName = @TProject
                          AND BB_Billable = 1
                          AND bb_momentvandedagname = 'Avond(17:30-24:00)') +
                          
                          (select cast(cast(sum(New_Durationorig)  as decimal(13,2)) / 60 as decimal(13,2)) * 190 FROM FilteredBB_urenregistratie 
                          where BB_werkzaamhedenName not like 'GENERIEK%'
                          AND datepart(month,bb_datum) = @TDate 
                          AND datepart(year,bb_datum)= @TYear
                          AND BB_ProjectIdName = @TProject
                          AND BB_Billable = 1
                          AND bb_momentvandedagname = 'Weekend') as TOTAAL,
                          
                         

Answer : MSSQL query count te values of te outut from te subquerys


SELECT DISTINCT
ISNULL( (select cast(cast(sum(New_Durationorig) as decimal(13,2)) / 60 as
decimal (13,2)) * 95 FROM FilteredBB_urenregistratie
where BB_werkzaamhedenName not like 'GENERIEK%'
AND datepart(month,bb_datum) = @TDate
AND datepart(year,bb_datum)= @TYear
AND BB_ProjectIdName = @TProject
AND BB_Billable = 1
AND bb_momentvandedagname = 'Kantoortijden(08:30-17:30)'),0) +

ISNULL( (select cast(cast(sum(New_Durationorig) as decimal(13,2)) / 60 as decimal(13,2)) * 143 FROM FilteredBB_urenregistratie
where BB_werkzaamhedenName not like 'GENERIEK%'
AND datepart(month,bb_datum) = @TDate
AND datepart(year,bb_datum)= @TYear
AND BB_ProjectIdName = @TProject
AND BB_Billable = 1
AND bb_momentvandedagname = 'Avond(17:30-24:00)'),0) +

ISNULL( (select cast(cast(sum(New_Durationorig) as decimal(13,2)) / 60 as decimal(13,2)) * 190 FROM FilteredBB_urenregistratie
where BB_werkzaamhedenName not like 'GENERIEK%'
AND datepart(month,bb_datum) = @TDate
AND datepart(year,bb_datum)= @TYear
AND BB_ProjectIdName = @TProject
AND BB_Billable = 1
AND bb_momentvandedagname = 'Weekend'),0 ) as TOTAAL,

Random Solutions  
 
programming4us programming4us