Hi
I really could do with a bit of advice/help.
I'm currently in the process of moving a myDBR instance from MySQL to SQL Server.
I have several crosstab reports and they are all give me a headache in converting - primarily to do with the group by statement.
For example
Here is the MySQL code:
01.
select
b.tblGroup_Cat_Desc
as
"[MCat]"
,
02.
c.subcategory
as
"[SCat]"
,
03.
d.tblcompanies_comp
as
"Company[Comp]"
,
04.
if(b.tblGroup_CAT_ID
in
(20),ifnull(
sum
(a.pl_val),0)*-1,ifnull(
sum
(a.pl_val),0))
as
"Value, $[Val]"
,
05.
a.pl_company
as
"[bcomp]"
,
06.
a.pl_period
as
"[bdate]"
,
07.
a.pl_subcat
as
"[scat]"
,
08.
a.pl_maincat
as
"[mcat]"
,
09.
f.b_maincat
as
"[bcat]"
,
10.
inRType
as
"[rType]"
,
11.
if(f.b_maincat=20,ifnull(f.b_val,0),ifnull(f.b_val,0)*-1)
as
"Budget, $[BVal]"
,
12.
null
as
"Variance[bVar]"
,
13.
null
as
"% Var.[pVar]"
14.
from
tmp_pandl a
15.
join
tblgroup_coa_category b
on
a.pl_maincat=b.tblGroup_CAT_ID
16.
left
outer
join
tblgroup_coa_subcat c
on
a.pl_subcat=c.subcatID
17.
join
tblcompanies d
on
a.pl_company=d.tblcompanies_ID
18.
join
(
SELECT
pl_subcat
as
pcat
FROM
tmp_pandl
where
iuser=inLogin
group
by
1
HAVING
sum
(pl_val) !=0) e
on
a.pl_subcat=e.pcat
19.
left
outer
join
budget_sum f
on
a.pl_subcat=f.b_subcat
20.
where
a.iuser=inLogin
/*and a.pl_val!=0*/
and
d.Ops=0
21.
group
by
a.pl_company,a.pl_subcat
22.
order
by
d.tblcompanies_ID,b.tblGroup_CAT_ID,c.subcatID;
The issue I'm getting is that T-SQL requires me to add nearly every field in the above query to the group by statement. All the fields from Value to Budget are hidden are are used as parameters for linked reports. The above works as expected in MySQL but I have to add so many fields to the group by statement in T-SQL I end up getting duplicate lines in the report.
As I said I have so many similar reports to I was hoping you could give me a steer on the best way to rewrite the above.
Many thanks
Jake