I'm using Crystal XI on SQL Server 2005.
I've seen a couple of posts on the topic but need some help.
I don't use SQL Expressions often, so may just need an example or two there.
I was attempting to sort on my variance formula: Sum ({@Current}, {sales_register.cust_name})-Sum ({@LastYear}, {sales_register.cust_name}). Here are the Current & Last Year formulas
{@Current}: if {sales_register.invoice_date} in YearToDate then
{sales_register.sub_amt}
{@LastYear}: if ({sales_register.invoice_date}) = LastYearYTD
then {sales_register.sub_amt}
Based on the posts I've read, I understand I cannot sort on a field which can not be summarized. It has been suggested I do the sum in the view. I'm attempting to do that, but it looks like TSQL doesn't have YearToDate adn LastYearYTD functions.
My report is grouping by the customer's name. Below is the view upon which the report is based. You see where I attempted to get the current_sub_amt in the view, but got stuck. Therefore, I thought I'd go back to Crystal Reports and try the SQL Expressions route. Any help would be greatly appreciated.
Thanks!
select -- invoice
ivc.batch_no,
ivc.invoice_no,
--Added by DLW 06/29/2011
coalesce(ivc.orig_invoice_no, ivc.invoice_no) as orig_ivc_no,
ivc.invoice_date,
ivc.branch_code,
ivc.customer_id,
current_sub_amt = (select sum(ivc2.sub_amt)
from invoice ivc2
where ivc.invoice_date in year
ivc.cust_name,
ivc.sub_amt,
-- invoice group
ig.doc_no,
doc_type = case
when ig.doc_type IN ('CBL', 'CO', 'COL') then 'CO'
when ig.doc_type IN ('WO', 'WOA', 'WOS', 'WOT') then 'WO'
when ig.doc_type IN ('SO', 'SOL', 'SOS', 'SSL') then 'SO'
when ig.doc_type IN ('IA', 'IAL') then 'IA'
when ig.doc_type IN ('CLH', 'CLA', 'CLT') then 'CLH'
else ig.doc_type
end,
ig.customer_po
from invoice ivc
join invoice_group ig on ig.invoice_no = ivc.invoice_no
join currency cu on cu.curr_code = ivc.curr
I've seen a couple of posts on the topic but need some help.
I don't use SQL Expressions often, so may just need an example or two there.
I was attempting to sort on my variance formula: Sum ({@Current}, {sales_register.cust_name})-Sum ({@LastYear}, {sales_register.cust_name}). Here are the Current & Last Year formulas
{@Current}: if {sales_register.invoice_date} in YearToDate then
{sales_register.sub_amt}
{@LastYear}: if ({sales_register.invoice_date}) = LastYearYTD
then {sales_register.sub_amt}
Based on the posts I've read, I understand I cannot sort on a field which can not be summarized. It has been suggested I do the sum in the view. I'm attempting to do that, but it looks like TSQL doesn't have YearToDate adn LastYearYTD functions.
My report is grouping by the customer's name. Below is the view upon which the report is based. You see where I attempted to get the current_sub_amt in the view, but got stuck. Therefore, I thought I'd go back to Crystal Reports and try the SQL Expressions route. Any help would be greatly appreciated.
Thanks!
select -- invoice
ivc.batch_no,
ivc.invoice_no,
--Added by DLW 06/29/2011
coalesce(ivc.orig_invoice_no, ivc.invoice_no) as orig_ivc_no,
ivc.invoice_date,
ivc.branch_code,
ivc.customer_id,
current_sub_amt = (select sum(ivc2.sub_amt)
from invoice ivc2
where ivc.invoice_date in year
ivc.cust_name,
ivc.sub_amt,
-- invoice group
ig.doc_no,
doc_type = case
when ig.doc_type IN ('CBL', 'CO', 'COL') then 'CO'
when ig.doc_type IN ('WO', 'WOA', 'WOS', 'WOT') then 'WO'
when ig.doc_type IN ('SO', 'SOL', 'SOS', 'SSL') then 'SO'
when ig.doc_type IN ('IA', 'IAL') then 'IA'
when ig.doc_type IN ('CLH', 'CLA', 'CLT') then 'CLH'
else ig.doc_type
end,
ig.customer_po
from invoice ivc
join invoice_group ig on ig.invoice_no = ivc.invoice_no
join currency cu on cu.curr_code = ivc.curr