Hi,
I'm using SQL Server 2005 to create a query to use in an Access 2003 report.
The SQL statement is as follows:
SELECT dbo.tbl_entities.fld_entit
yname, dbo.tbl_codes.fld_year, dbo.tbl_categories.fld_cat
egoryname,
dbo.tbl_subcategories.fld_
subcategor
yname,
dbo.tbl_budget.fld_purpose
, dbo.tbl_budget.fld_unitcos
t * dbo.tbl_budget.fld_quantit
y AS fld_total
FROM dbo.tbl_budget INNER JOIN
dbo.tbl_categories ON dbo.tbl_budget.fld_categor
ycode = dbo.tbl_categories.fld_cat
egorycode INNER JOIN
dbo.tbl_subcategories ON dbo.tbl_budget.fld_subcate
gorycode = dbo.tbl_subcategories.fld_
subcategor
ycode INNER JOIN
dbo.tbl_codes ON dbo.tbl_budget.fld_code = dbo.tbl_codes.fld_code INNER JOIN
dbo.tbl_entities ON dbo.tbl_codes.fld_entityco
de = dbo.tbl_entities.fld_entit
ycode
The result i get is as follows:
Entity Year Category Subcategory Purpose Total
IGB 20072008 Hardware Others Exp 9000.0
IGB 20072008 Office Equipment Others Exp 1000.0
IGB 20072008 Hardware Laptop Ren 2000.0
IGB 20072008 Hardware Desktop Ren 4000.0
IGB 20072008 Hardware Laptop Prj 4000.0
IGB 20072008 Hardware Laptop Prj 4000.0
I need to modify the SQL statement, so that instead of one field as "purpose" and another field as "total", i have three fields as "total_exp", "total_ren" and "total_prj" So basically, i want a total field that's based on a criteria of another field in the same table. So my final query will look like this:
Entity Year Category Subcategory Total_Exp Total_Ren Total_Prj
IGB 20072008 Hardware Others 9000.0 0 0
IGB 20072008 Office Equipment Others 1000.0 0 0
IGB 20072008 Hardware Laptop 0 2000.0 0
IGB 20072008 Hardware Desktop 0 4000.0 0
IGB 20072008 Hardware Laptop Prj 8000.0
Start Free Trial