I am writing an SSRS report to create an invoice.
In my report, I have a dataset whcih runs the following query:
select Customer, Name, BillAddress, BillCity, BillState, BillZip from ARCM where ARCM.Customer = #BillCustomer and ARCM.CustGroup = 1
As you can see, I have a parameter called '#BillCustomer'.
I have another dataset which runs this query:
select Co, Customer, Invoice, TransDate, DueDate, PayTerms, CustRef from ARBH
Where Invoice = #Invoice
How can I change my report so that #BillCustomer does not need to be manually entered when I run the report however, it gets its value from the Customer field in the second dataset?
Could you change your Customer dataset to use the parameter #Invoice directly and change the query to
select Customer, Name, BillAddress, BillCity, BillState, BillZip
from ARCM where ARCM.Customer IN (
select Customer
from ARBH
Where Invoice = #Invoice) and ARCM.CustGroup = 1
Or using JOIN in above query.
Related
I have a sub-report that returns the following....
SELECT
SUM (SorDetail.MPrice) OVER (PARTITION BY SorDetail.SalesOrder, [CusSorDetailMerch+].InvoiceGrouping) AS GroupTotal,
SorDetail.SalesOrder,
SorDetail.SalesOrderLine,
SorDetail.MStockCode,
SorDetail.MStockDes,
[CusSorDetailMerch+].InvoiceGrouping,
SorDetail.MOrderQty,
SorDetail.MPrice,
[CusSorDetailMerch+].SerialNumber
FROM
SorDetail
INNER JOIN
[CusSorDetailMerch+] ON SorDetail.SalesOrder = [CusSorDetailMerch+].SalesOrder
AND SorDetail.SalesOrderLine = [CusSorDetailMerch+].SalesOrderInitLine
WHERE
(dbo.SorDetail.SalesOrder = '000000000' + '{?SalesOrder}')
AND (dbo.SorDetail.SalesOrderInitLine = '{?Line}')
ORDER BY
[CusSorDetailMerch+].InvoiceGrouping
It returns this which is what I want:
Data Returned
What I just cant seem to do id to add a column that sums the different groups and separates the groups like this:
enter image description here
I have tried everything but cannot get the sums individually
I'm trying to create a report where I have to get the top 10 facilities that have a specific action code. I'm using 3 different tables (customer.id) customers pertaining to those facilities, the facility information ( facility.id), and action code( action.id) I'm fairly new to writing queries so here is what
SELECT
customer.id_NO,
customer.id_CLIENT,
facility.id_NAME_1 ,
action.id_ACTION_CODE
FROM
CDS.action.id, CDS.customer.id, CDS.facility.id
WHERE
facility.id _NO = customer.id _CLIENT
AND action.id_CUSTOMER_NO = customer.id _NO
I want to count every time the action code 'CDQ' occurs per facility
SELECT COUNT ( action.id_ACTION_CODE)
FROM CDS.action.id
WHERE action.id_ACTION_CODE = 'CDQ'
Is it possible to get all in a single query? I'm using Crystal Reports
You can create a formula and use sum on this formula:
If {action.id_ACTION_CODE} = "CDQ" Then 1 Else 0
I'm trying to learn SQL (through a company guide).
I have a list of invoices in a table and a tax code associated with one.
All of the invoices have one tax code, except number 1000001 which has two (and therefore two records in dbo.InvoiceTaxBreakDown.
The exercise wants me to create the variables TaxCode1 and TaxCode2. All except one record should have 'NULL' in TaxCode2.
This is my code:
SELECT
InvoiceNo,
TaxCode1 =
(
SELECT
TOP 1 T.TaxCode
FROM
dbo.InvoiceTaxBreakDown as T
WHERE
I.InvoiceGUID = T.InvoiceGUID
ORDER BY
T.TaxCode DESC
)
,
TaxCode2 =
(
SELECT
TOP 1 T.TaxCode
FROM
dbo.InvoiceTaxBreakDown as T
WHERE
I.InvoiceGUID = T.InvoiceGUID
ORDER BY
T.TaxCode ASC
)
FROM
dbo.InvoiceTaxBreakDown as I
I'm not sure if I even need to reference two data sources..
Only the first record is correct! Please help.
[Output][1]
I was just wondering how could I count the number of a specific equipment..
SELECT
EQUIPMENTS.DESCRIPTION AS [EQUIPMENT TYPE],
Count(EQUIPMENTS.EQNAME) AS QUANTITY,
(SELECT Count(EQUIPMENTS.CONDITION) FROM EQUIPMENTS WHERE EQUIPMENTS.CONDITION = 'Functional') AS WORKING,
(SELECT Count(EQUIPMENTS.CONDITION) FROM EQUIPMENTS WHERE EQUIPMENTS.CONDITION = 'Non-Functional') AS [NON-WORKING]
FROM EQUIPMENTS
GROUP BY EQUIPMENTS.DESCRIPTION;
this query returns the following :
EQUIPMENT NAME : PROJECTOR
QUANTITY : 3
WORKING : 2
NON-WORKING :1
Now if I add another equipment which has a different type, for example CALCULATOR, it would have the same count of WORKING AND NON-WORKING which only is for the PROJECTOR. How do I Make it such that it also counts the quantity of the Calculator and the number of working and non-working itself? I mean whenever I add another equipment which has a specific description, the query would also count it independently?
I'm using VB.NET and this query is made in MS ACCESS 2007.
Use IIf() expressions to return 1 when the condition is satisfied, and 0 when not. Then Sum those values.
SELECT
e.DESCRIPTION AS [EQUIPMENT TYPE],
Count(e.EQNAME) AS QUANTITY,
Sum(IIf(e.CONDITION = 'Functional', 1, 0)) AS WORKING,
Sum(IIf(e.CONDITION = 'Non-Functional', 1, 0)) AS [NON-WORKING]
FROM EQUIPMENTS AS e
GROUP BY e.DESCRIPTION;
I had received some really good help earlier, and I appreciate it.
I have another record selection snafu.
I have a parameter that I need to set as the end date.
I need to pull the most recent state before the end date from a table titled state_change.
I need to exclude any records from the report who are not in the required states at that period in time.
state is set currently to be state_change.new_state
( {#grouping} = "Orders" and rec_date < {?endDate} and {#state} in [0,2,5] )
OR
( {#grouping} = "Stock" and rec_date < {?endDate} and {#state} in [1,2,3,5,7] )
If I could run a SQL query to pull this information, it would probably work, but I cannot figure out how to do it.
Essentially, I need #state to be:
Select max(new_state)
From state_change
where change_time < {?endDate}
but on a per item level.
Any help would be appreciated.
You'll probably need to use a command object with a parameter for your end date, or create a parameterized stored procedure. The command object will allow you to enter all the sql you need, like joining your results with the max newState value before the end date:
select itemID, new_state, rec_date, max_newState from
(select itemID, new_state, rec_date from table) t inner join
(Select itemID, max(new_state) as max_newState
From state_change
where change_time < {?endDate}
group by itemID) mx on t.itemid = mx.itemID and t.new_state = mx.max_newState
I can't tell if your orders and stock groupings are in the same table, so I'm not sure how you need to limit your sets by the correct state values.