It will make it easier to determine a solution if all columns and types are known.
IF :end_day > 17
SELECT dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg as 'wave',
'New' as 'status',
sum(dbo.ord_hdr.crd_tot_nbr) as 'tot_os',
sum(dbo.ord_hdr.aces_tot_nbr) as 'tot_acc',
sum(dbo.ord_hdr.prpk_tot_nbr) as 'tot_pp',
sum(dbo.ord_hdr.addon_tot_nbr) as 'tot_sao',
' ' as 'ws_os',
' ' as 'ws_acc',
' ' as 'ws_pp',
' ' as 'ws_sao',
' ' as 'wc_os',
' ' as 'wc_acc',
' ' as 'wc_pp',
' ' as 'wc_sao'
FROM dbo.ord_hdr
WHERE ( convert(integer,dbo.ord_hdr.jul_rlse_dy) >= :start_day) AND
( convert(integer,dbo.ord_hdr.jul_rlse_dy) <= :end_day)
group by dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg
ELSE
SELECT dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg as 'wave',
'New' as 'status',
sum(dbo.ord_hdr.crd_tot_nbr) as 'tot_os',
sum(dbo.ord_hdr.aces_tot_nbr) as 'tot_acc',
sum(dbo.ord_hdr.prpk_tot_nbr) as 'tot_pp',
sum(dbo.ord_hdr.addon_tot_nbr) as 'tot_sao',
' ' as 'ws_os',
' ' as 'ws_acc',
' ' as 'ws_pp',
' ' as 'ws_sao',
' ' as 'wc_os',
' ' as 'wc_acc',
' ' as 'wc_pp',
' ' as 'wc_sao'
FROM dbo.ord_hdr
WHERE ( convert(integer,dbo.ord_hdr.jul_rlse_dy) >= :start_day) OR
( convert(integer,dbo.ord_hdr.jul_rlse_dy) <= :end_day)
group by dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg
SELECT dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg as 'wave'
, 'New' as 'status'
, sum(dbo.ord_hdr.crd_tot_nbr) as 'tot_os'
, sum(dbo.ord_hdr.aces_tot_nbr) as 'tot_acc'
, sum(dbo.ord_hdr.prpk_tot_nbr) as 'tot_pp'
, sum(dbo.ord_hdr.addon_tot_nbr) as 'tot_sao'
, ' ' as 'ws_os'
, ' ' as 'ws_acc'
, ' ' as 'ws_pp'
, ' ' as 'ws_sao'
, ' ' as 'wc_os'
, ' ' as 'wc_acc'
, ' ' as 'wc_pp'
, ' ' as 'wc_sao'
FROM dbo.ord_hdr
WHERE dbo.ord_hdr.jul_rlse_dy >= :start_day
AND dbo.ord_hdr.jul_rlse_dy < :end_day
GROUP
BY dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg
WHERE (( convert(integer,dbo.ord_hdr.jul_rlse_dy)) BETWEEN :start_day AND :end_day OR
( convert(integer,dbo.ord_hdr.jul_rlse_dy)) BETWEEN :start_day2 AND :end_day2)
SELECT dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg as 'wave',
'New' as 'status',
sum(dbo.ord_hdr.crd_tot_nbr) as 'tot_os',
sum(dbo.ord_hdr.aces_tot_nbr) as 'tot_acc',
sum(dbo.ord_hdr.prpk_tot_nbr) as 'tot_pp',
sum(dbo.ord_hdr.addon_tot_nbr) as 'tot_sao',
' ' as 'ws_os',
' ' as 'ws_acc',
' ' as 'ws_pp',
' ' as 'ws_sao',
' ' as 'wc_os',
' ' as 'wc_acc',
' ' as 'wc_pp',
' ' as 'wc_sao'
FROM dbo.ord_hdr
WHERE :start_day < :end_day AND
( ( convert(integer,dbo.ord_hdr.jul_rlse_dy) >= :start_day) AND
( convert(integer,dbo.ord_hdr.jul_rlse_dy) <= :end_day) )
group by dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg
UNION ALL
SELECT dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg as 'wave',
'New' as 'status',
sum(dbo.ord_hdr.crd_tot_nbr) as 'tot_os',
sum(dbo.ord_hdr.aces_tot_nbr) as 'tot_acc',
sum(dbo.ord_hdr.prpk_tot_nbr) as 'tot_pp',
sum(dbo.ord_hdr.addon_tot_nbr) as 'tot_sao',
' ' as 'ws_os',
' ' as 'ws_acc',
' ' as 'ws_pp',
' ' as 'ws_sao',
' ' as 'wc_os',
' ' as 'wc_acc',
' ' as 'wc_pp',
' ' as 'wc_sao'
FROM dbo.ord_hdr
WHERE :start_day > :end_day AND
( ( convert(integer,dbo.ord_hdr.jul_rlse_dy) >= :start_day) OR
( convert(integer,dbo.ord_hdr.jul_rlse_dy) <= :end_day))
group by dbo.ord_hdr.jul_rlse_dy + dbo.ord_hdr.rlse_cycle + dbo.ord_hdr.trlr_seg
Title | # Comments | Views | Activity |
---|---|---|---|
White board coding practice | 3 | 61 | |
Count UNIQUE results in a field from an MS Access database | 6 | 45 | |
SUM 2 INTEGER ARRAYS INTO 1 | 10 | 63 | |
Create calculation and case in query with times | 13 | 13 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
13 Experts available now in Live!