Wednesday, October 31, 2007

There's probably a simpler approach to this.

Just a quick code post at work, I'd wanted a Halloween image which I clearly don't have access to at work, so keeping it just to the code, and maybe I'll put up something Halloween-y later on (assuming I have images that aren't merely leaning to the gothic side of things) and by later I do mean much later, as in another day, as I'll probably be playing Hellgate all evening.

Anyways, SQL madness

select
DATEDIFF(n, pj_print_time_on, pj_print_time_off) [Print Minutes]
,(CAST(pj_print_counter_end AS int) - CAST(pj_print_counter_start AS int)) [Print Total]
,pj_print_spoilage_qty [Print Spoil]
,(((CAST(pj_print_counter_end AS int) - CAST(pj_print_counter_start AS int))) / (DATEDIFF(n, pj_print_time_on, pj_print_time_off))) [Print per Minute]
,pj_comments [Comments]
,DATEDIFF(n, pj_folding_time_on, pj_folding_time_off) [Fold Minutes]
,pj_total_folded [Fold Total]
,((pj_total_folded)/(DATEDIFF(n, pj_folding_time_on, pj_folding_time_off))) [Fold per Minute]
,pj_folding_spoilage_qty [Fold Spoil]
,DATEDIFF(n, pj_insert_time_on, pj_insert_time_off) [Insert Minutes]
,pj_insert_total [Insert Total]
,pj_insert_spoilage_qty [Insert Spoilage]
,((pj_insert_total) / (DATEDIFF(n, pj_insert_time_on, pj_insert_time_off))) [Insert per Minute]
from print_jobs
where DATEDIFF(n, pj_print_time_on, pj_print_time_off) > 0
AND (CAST(pj_print_counter_end AS int) - CAST(pj_print_counter_start AS int)) > 0
AND DATEDIFF(n, pj_folding_time_on, pj_folding_time_off) > 0
AND DATEDIFF(n, pj_insert_time_on, pj_insert_time_off) > 0
AND pj_entered_date_time > @StartDate and pj_entered_date_time < @EndDate

All it really lacks to truly impress myself is variable declaration to avoid the repeated usage of the mathematics in getting the 'per minute' values.