Hi
I may have confused you a bit.
The report I'm running is not a linked report = it is a report that accepts user parameters.
I'm running the report as follows:
CREATE PROCEDURE sp_DBR_Residual_Value
(inSite_ID tinyint(3),inPhase_ID tinyint(3),inLogin varchar(30))
As I said previously the report runs fine. I can retrieve the Site Name and Phase Name using the user parameters but I can't find a way of putting these retrieved fields in the report title. Each method I've used results in 'unknown column in the field list' for example:
select 'dbr.title',Site,Phase;
Below is the query I'm using.
Thanks
Jake
SELECT
b.Site_ID as 'Site_ID[SiteID]',
b.Site_Name as 'Site[Site]',
c.tblContractXIDJobAnalysis as 'PhaseID[PhaseID]',
e.tblJobAnalysis_JobAnalysis as 'Phase[Phase]',
right(a.tblContractXidJobNo,length(a.tblContractXidJobNo)-locate("_",a.tblContractXidJobNo)) as 'Plot[Plot]',
h.tblSalesInv_Net as 'Final Price',
d.tblTender_Amount as 'Build Tender[Tender]',
truncate((ifnull(d.tblTender_Amount,0)- a.Tender_FitOut),0) as 'Shell Tender[SCosts]',
a.Tender_FitOut as 'FitOut Tender[FCosts]',
a.Var_Construct as 'Build Vars[BVar]',
a.Var_Customer as 'Cust. Vars[CVar]',
truncate((ifnull(d.tblTender_Amount,0)+a.Var_Construct+a.Var_Customer),0) as 'Total Costs[TCosts]',
f.Valuations as 'Valuations[Vals]',
g.Materials as 'Materials[Mats]',
ifnull(f.Valuations,0)+ ifnull(g.Materials,0) as 'Total Vals[TVals]',
case
when ifnull(f.Valuations,0) > truncate((ifnull(d.tblTender_Amount,0)- a.Tender_FitOut),0) then 0
else truncate((ifnull(d.tblTender_Amount,0)- a.Tender_FitOut) - ifnull(f.Valuations,0),0)
end as 'Shell Res. Spend[SVal]',
case
when d.tblTender_Amount is null then 0
else (ifnull(d.tblTender_Amount,0)+a.Var_Construct+a.Var_Customer) - ifnull(f.Valuations,0) - ifnull(g.Materials,0)
end as 'Total Res. Spend[RVal]'
FROM
hilmark.tblsitesplotsjake a
INNER JOIN hilmark.tblsitesjake b
ON a.Site_ID = b.Site_ID
INNER JOIN hilmark.tblcontracts c
ON a.tblContractXidJobNo = c.tblContractXidJobNo
LEFT OUTER JOIN hilmark.tbltender d
ON a.tblContractXidJobNo = d.tblTender_JobNo
INNER JOIN hilmark.tbljobanalysis e
ON c.tblContractXIDJobAnalysis = e.tblJobAnalysis_ID
LEFT OUTER JOIN
(SELECT
hilmark.tblcertificates.tblCert_XIDJob,
SUM(hilmark.tblcertificates.tblCertificates_AllocateWIP) as Valuations
FROM
hilmark.tblcertificates
group by
hilmark.tblcertificates.tblCert_XIDJob) as f
ON a.tblContractXidJobNo = f.tblCert_XIDJob
LEFT OUTER JOIN
(SELECT
hilmark.tblMaterials.tblMaterials_XIDJob,
SUM(hilmark.tblMaterials.tblMaterials_AllocateWIP) as Materials
FROM
hilmark.tblMaterials
group by
hilmark.tblMaterials.tblMaterials_XIDJob) as g
ON a.tblContractXidJobNo = g.tblMaterials_XIDJob
LEFT OUTER JOIN hilmark.tblsalesinv h
ON a.tblContractXidJobNo = h.tblSalesInv_XIDJob
where (a.Site_ID = inSite_ID or inSite_ID = '%') and (e.tblJobAnalysis_ID = inPhase_ID or inPhase_ID = '%')
Order by
a.Site_ID ASC,
e.tblJobAnalysis_ID ASC,
a.tblContractXidJobNo ASC;