I am building an SSRS report that includes 3 parameters (supplierid, startdate and enddate) but I am trying to implement an optional parameter (one that allows a blank value) called customerid. here is what I have for code:
WHERE (invoice_hdr.company_no = 1) AND
(supplier.supplier_id = #supplierid) AND
(#customerid =
CASE #customerid
WHEN customer.customer_id THEN customer.customer_id
ELSE 0
END) AND
(invoice_hdr.invoice_date >= DATEADD(DAY,-365,GETDATE()) AND
--(invoice_hdr.invoice_date >= #startdate) AND
--(invoice_hdr.invoice_date <= #enddate) AND
(invoice_line.tax_item = 'N') AND
I am trying to say: IF a value is put into the customerid parameter then return that value with the other filters BUT if no value is placed in that parameter then bypass that filter and continue on running the query like it is not there. I have changed the parameter settings in SSRS to allow a blank/null value but the report errors out. Is there anyway to do this? is this an issue in SSRS?
I am having trouble doing this, any help would be appreciated.
UPDATE AFTER INCLUDING:
(
customer.customer_id = #customerid
OR
#customerid =''
) AND
and changing the parameter in SSRS this is the error message:
enter image description here
BUT if I run it without that parameter and section of code the report works.
Not sure what the issue is without the error message but I usually use something like:
AND (
customer.customer_id = #customerid
OR
#customerid IS NULL
)
This will include all IDs that match the parameter or ALL IDs if the parameter is NULL.
Alternative is to do this
AND (
customer.customer_id = #customerid
OR
#customerid =''
)
the on your customer parameters, set the parameter to
Allow Blankvalue ("")
this way, if you do need to select the customer, you do not have to untick the NULL before using the parameter
Related
I have created the SSRS report which contains CarID, RegistrationNo, CarID_creation_date and Reg_Date.
Also I have created the parameters for dates by which I can select the date range. But how can I create a report in which if I enter only CarID then only CarID_creation_date should get activate and other field gets blurred out/disabled, and vice versa.
I have tried with a query so from backend using case statement and its working fine, but I wanted to add this visualization in SSRS report, so how can I add the same? Report_Design_Image
Currently using below code:
IF #CarID='' and #RegID=''
Begin SELECT * FROM Car_Details END
ELSE
IF #CarID=<>'' and #RegID='' Begin SELECT * FROM Car_Details where CarID_creation_date Between #CarID_Start_Date and #CarID_End_Date
ELSE
IF #CarID='' and #RegID=<>'' Begin SELECT * FROM Car_Details where Reg_date Between #Reg_Start_Date and #Reg_End_Date
END
IF #CarID=<>'' and #RegID=<>'' Begin SELECT * FROM Car_Details where CarID_creation_date Between #CarID_Start_Date and #CarID_End_Date AND Reg_date Between #Reg_Start_Date and #Reg_End_Date
END
You cannot conditionally turn parameters on and off in SSRS.
The only way you can do this is if a value is entered in Carid, then it can look at only the dates for car_id_creation_date. You can do this in your datasource - if you are suing SQL as your backend, you could make your where clause to be something like this :
where
(isnull(#carid,'')<>'' and sometable.datecolumn between #carid_creationstart and #carid_creationend)
or
(isnull(#reg_no,'')<>'' and sometable.datecolumn2 between #reg_no_creationstart and #reg_no_creationend)
in your SSRS front end, you can set the parameter to be set to be NULL and blank
The alternative is to have a drop down parameter called "Category" and then make the select values as Car_id and Reg_id. Then you will have only one set of date parameter that can be used for both categories.
so your where statement will be something like
where
(#category = 'car_id' and sometable.datecolumn between #start_date and #end_date)
or
(#category = 'reg_id' and sometable.datecolumn2 between #start_date and #end_date)
I have a tablix that is linked to DataSet1.
DataSet1 uses the following TSQL code
select ir.SourceRef as Account_Ref,
rab.BalanceFromDate,
rab.ClosingBalance Current_Balance,
ra.Account_ID as rserial,
ra.Current_Balance as Current_Balance
from db1..RentAccountBalance rab
left join db1..ImportReference ir on ir.EntityID = rab.AccountId and ir.EntityType='XXXX.XXX.X.XX'
left join db2..RentAccounts ra on convert(varchar(50),ra.Account_ID) = ir.SourceRef
where ir.SourceRef = '12857'
order by rab.AccountBalanceId
As I know that there is no ir.SourceRef that is equal to 12857, the result set is blank. Therefore, my tablix comes back just blank.Is there a way that if no results are returned that a text of say "All Accounts are OK." be displayed by the report instead?
Hope that's clear?
Thanks
You can try expression like:
=IIF(IsNothing(Fields!FieldName.Value, "Accounts are OK", Fields!FieldName.Value))
Or if you want to check if there is no data at all, you can try to throw an error in TSQL in following:
--add this line to the end of query:
IF ##ROWCOUNT = 0 RAISERROR('Accounts are OK', 16, 1)
If you use a Stored Procedure you can then insert your Select statement data into a table variable before returning it. From this you can perform a check on its contents before it is returned to the report.
For example if you populate a table of data you wish to return as follows
INSERT INTO #ReturnTable (Account_Ref, ...)
SELECT ir.SourceRef, ...
You can then query it's contents by using a command such as
IF (SELECT COUNT(*) FROM #ReturnTable) = 0
BEGIN
INSERT INTO #ReturnTable (Account_Ref, ...)
SELECT 'All Accounts are OK', ...
END
You can then perform a check within the report to see if the Account_Ref is 'All Accounts are OK', and if so display the report appropriately. You can even set the entire report's contents inside a rectangle with the visibility set to the result of
=iif(First(Fields!Account_Ref.Value) = "All Accounts are OK", false, true)
You can layer another object (an information message perhaps) on top of this with the inverse of this visibility set.
I am attempting to change a value of a field for products on Volusion shopping engine. The field I want to set is 'HideProduct' to 'Y' if it's children products are equivalent to 0 (negative stocks also count as zero). However, some products don't have children, which are ignored.
I don't have direct access to the server or database, and this script is being passed though with the errors suppressed. The error I get is simply "An error has occurred. Please try your request again, or contact customer service for assistance. Thank you." They don't offer customer support for SQL.
This is the script I am trying to run:
UPDATE
Products_Joined
SET
HideProduct = 'Y'
WHERE
-- Only apply to products where there are no in stock children
0 = SUM(
SELECT
CASE
WHEN Pb.DoNotAllowBackOrders = 'N' THEN 1
WHEN Pb.StockStatus < 0 THEN 0
ELSE Pb.StockStatus
END
FROM
Products_Joined Pb
WHERE
ProductCode = Pb.IsChildOfProductCode
)
AND
--Only apply to products with children
0 < TOTAL(
SELECT
Pc.StockStatus
FROM
Products_Joined Pc
WHERE
ProductCode = Pc.IsChildOfProductCode
)
I am attempting to pass the Product Code of the UPDATE part of the script into the SELECT parts of the code. I think that's where the issue might be.
Why is it that when I run the query in Management Studio with the following where clause, it returns the data correctly when the cash_date equals the parameter, FromDate.
FILMTRAN.cash_date >= (#FromDate) AND
However, when I copy the same query to SSRS it no longer includes the data where the #FromDate equals the cash_date. The user enters in the parameter in SSRS. I even did a test where I displayed the full date including the time and did an if statement that returned "yay" if they matched or "no" if they did not. Even according to SSRS, they match, but than why is my data not being returned when it occured on the same day?! I am dumbfounded this is not working, when it clearly works in management studio.
I have even tried adding a dateadd function into my sql statement, which again responds correctly in management studio but not ssrs.
Edit: I tested the >= using a much simpler 3 line query and it worked as intended but it is still not working for my query, which works in management studio but not SSRS. So now I am thinking there is some very specific bug associated with something in my longer query which I have attached. To test my code in management studio I declare the variables as seen below. However, I delete this code when I import my query into SSRS and instead create the parameters within SSRS(just as I have always done, with no problems).
DECLARE #FromDate AS DATETIME
SET #FromDate = '1-Oct-2013'
DECLARE #ToDate AS DATETIME
SET #ToDate = '8-Apr-2015'
DECLARE #Loan AS VARCHAR(20)
SET #Loan = 'TAX_B'
SELECT distinct LOANMAST.loan,
CARDINDX.DESCRIPTION AS BorrowerName,
CARDINDX.contact_name,
CARDINDX.in_care_of,
--loan_ipt.interest,
CARDINDX.mail_address1,
CARDINDX.mail_address2,
CARDINDX.mail_city,
CARDINDX.mail_state,
CARDINDX.mail_country,
LOANMAST.closed_date,
PROPERTY.STATE,
CARDINDX.MAIL_ZIP_CODE,
PROPERTY.address1,
PROPERTY.address2,
PROPERTY.city,
PROPERTY.ZIPCODE,
PROPERTY.country,
FILMTRAN.cash_date,
CASE FILMTRAN.TRAN_SUBTYPE WHEN 'REGINST' THEN 'Regular Collections'
WHEN 'PAC' THEN 'PAC'
WHEN 'CORREST' THEN 'Group Collection'
WHEN 'ESCROWTAX' THEN 'Tax Disbursement'
WHEN 'SUNDRY' THEN 'Tax Refund'
WHEN 'FULL PAY' THEN 'Payoff'
END AS TRANSUBTYPE,
FILMTRAN.TAX_ESCROW,
FILMTRAN.TRANSACTION079,
JK.taxescrowbalance,
CASE FILMTRAN.TRANSACTION079 WHEN 'COLLECTION' THEN FILMTRAN.TAX_ESCROW
WHEN 'DISBURSEMENT' THEN 0
END AS TAXESCROWCOLL,
CASE FILMTRAN.TRANSACTION079 WHEN 'DISBURSEMENT' THEN FILMTRAN.TAX_ESCROW *-1
WHEN 'COLLECTION' THEN 0
END AS TAXESCROWDIS
FROM LOANMAST LEFT OUTER JOIN BORROWER ON LOANMAST.loan=BORROWER.loan
LEFT OUTER JOIN LOANCOLL ON LOANMAST.loan=LOANCOLL.loan
LEFT OUTER JOIN PROPERTY ON LOANCOLL.code=PROPERTY.prop_code
LEFT OUTER JOIN BALHIST ON BALHIST.loan=LOANMAST.loan
LEFT OUTER JOIN CARDINDX ON BORROWER.SHORT_NAME=CARDINDX.SHORT_NAME
LEFT OUTER JOIN LOAN_IPT ON LOAN_IPT.short_name=CARDINDX.short_name
LEFT OUTER JOIN FILMTRAN ON FILMTRAN.loan=LOANMAST.loan
JOIN (
SELECT distinct FILMTRAN.loan, FILMTRAN.cash_date, FILMTRAN.transaction079 ,FILMTRAN.tax_escrow,
sum(FT.taxescrowcoll)+sum(FT.taxescrowdis)+isnull(BH.esc_tax_bal_p, 0) AS "TaxEscrowBalance"
from
FILMTRAN
LEFT OUTER JOIN (SELECT loan, accounting_date, esc_tax_bal_p,
rank () over (order by accounting_date desc) AS date_rank
FROM BALHIST
where loan = #Loan) BH ON BH.loan=FILMTRAN.loan
JOIN
(
SELECT loan, cash_date,
FILMTRAN.transaction079,
CASE FILMTRAN.TRANSACTION079 WHEN 'COLLECTION' THEN TAX_ESCROW
WHEN 'DISBURSEMENT' THEN 0
END AS TAXESCROWCOLL,
CASE FILMTRAN.TRANSACTION079 WHEN 'DISBURSEMENT' THEN TAX_ESCROW *-1
WHEN 'COLLECTION' THEN 0
END AS TAXESCROWDIS FROM FILMTRAN
WHERE loan = #Loan)
FT ON FT.loan=FILMTRAN.loan
where FT.cash_date <= FILMTRAN.cash_date
AND (BH.date_rank ='1' OR BH.accounting_date IS NULL)
AND (len(FT.transaction079) <= len(FILMTRAN.transaction079) OR FT.cash_date < FILMTRAN.cash_date)
GROUP BY FILMTRAN.loan,FILMTRAN.cash_date, FILMTRAN.transaction079, FILMTRAN.TAX_ESCROW, BH.esc_tax_bal_p) JK ON JK.loan=FILMTRAN.loan AND JK.cash_date = FILMTRAN.cash_date AND JK.transaction079=FILMTRAN.transaction079
WHERE
FILMTRAN.RVRS_REASON <> 'ERROR_CORR' AND
Loancoll.prim_ind = 'Y' AND
LOANMAST.loan_status <> '1_INQUIRY' AND
LOANMAST.loan_status <> '2_APP_ISS' AND
LOANMAST.loan_status <> '3_APP_ACC' AND
LOANMAST.loan_status <> '4_APPROVED' AND
LOANMAST.loan_status <> '5_COMMITTED' AND
LOANMAST.loan_status <> '9_DELN_SLF' AND
LOANMAST.loan_status <> '9_REJ_BRWR' AND
FILMTRAN.cash_date >= (#FromDate)
AND FILMTRAN.cash_date <= (#ToDate)
AND LOANMAST.loan = #Loan
AND FILMTRAN.tax_escrow <> 0
You have a date formatting issue.
Hopefully you are calling a stored procedure to generate your dataset.
If not, you should be!
To see what is happening you might want to output the dates that are getting passed through into a table - then have a look at that table once you have run the report. Obviously you will drop this table once your debugging is complete.
Make sure you store the dates in this table as text rather than DateTime.
Have a look at the diffrences when you run from SSRS and Management Studio.
I was unable to replicate this issue. In my system, using SSRS-2008, the results in SSRS are the same as in SQl-Server. I'm using a where clause with an SSRS parameter and a >= operator. I tested with both Text and Date/Time parameter types, and both worked fine.
I would suggest that you make sure that the datasource is the same as what you are querying in SQL server. Also, try entering the date without a time, if you are entering a time in the parameter.
For further assistance, please post your complete query (or a facsimile) and information on your table and parameter settings in SSRS.
EDIT:
Just taking a look at your query here, and I have a feeling that this may be the problem area:
where FT.cash_date <= FILMTRAN.cash_date
AND (BH.date_rank ='1' OR BH.accounting_date IS NULL)
AND (len(FT.transaction079) <= len(FILMTRAN.transaction079) OR FT.cash_date < FILMTRAN.cash_date)
Possibly could be stemming from confusion over the use of Filmtran without aliasing within the subquery, when it is already included in the main query? I would run the query without the two sub-queries in the From clause and see if the dates are as you'd expect, the add back in the subqueries one by one to determine the location of the issue.
Ok so the solution to my problem was dumber than I would like to admit. So in addition to stating my solution I will also suggest potential problems/solutions that relate to dates in SSRS/Management Studio:
Check the filters on the dataset within SSRS! This was my problem since I used a report template that had filters already on the dataset, even though I usually do all filters by hand in SQL management studio. (See picture below)
Make sure the time is correct, not just the date. For example, 10/1/2013 might appear but the actual value behind that date is something like 10/1/2013 5:43 PM. So then doing <= will not work if you are trying to include values that happened after 10/1/2013 5:43 PM but before 10/2/2013.
Make sure the regional date settings are the same for SSRS and SQL Server. For example, if one machine views dates in the European format of DD/MM/YYYY then it could cause problems if another user's machine is expecting the date to be in MM/DD/YYYY format.
Hey guys, first off all sorry, i can't login using my yahoo provider.
anyways I have this problem. Let me explain it to you, and then I'll show you a picture.
I have a access db table. It has 'report id', 'recpient id', and 'recipient name' and 'report req'. What the table "means" is that do the user using that report still require it or can we decommission it.
Here is how the data looks like (blocked out company userids and usernames):
*check the link below, I cant post pictures cuz yahoo open id provider isnt working.
So basically I need to have 3 select queries:
1) Select all the reports where for each report, ALL the users have said no to 'reportreq'. In plain English, i want a listing of all the reports that we have to decommission because no user wants it.
2) Select all the reports where the report is required, and the batchprintcopy is more then 0. This way we can see which report needs to be printed and save paper instead of printing all the reports.
3)A listing of all the reports where the reportreq field is empty. I think i can figure this one out myself.
This is using Access/VBA and the data will be exported to an excel spreadsheet. I just a simple query if it exists, OR an alogorithm to do it quickly. I just tried making a "matrix" and it took about 2 hours to populate.
https://docs.google.com/uc?id=0B2EMqbpeBpQkMTIyMzA5ZjMtMGQ3Zi00NzRmLWEyMDAtODcxYWM0ZTFmMDFk&hl=en_US
I suggest:
SELECT DISTINCT o.reportid, o.ReportReq
FROM All_Reports AS o
WHERE o.reportid Not In (SELECT reportid FROM All_Reports
WHERE reportreq <>"N" Or reportreq Is Null)
There is a problem with this query in that I note that the sample document has a value for batchprintcopies where reportreq is null, so here are three possibilities:
1 Exclude reports where reportreq is null:
SELECT reportid, SUM(batchprintcopies) FROM All_Reports
WHERE reportreq <>"N"
GROUP BY reportid
HAVING Sum(batchprintcopies)>0
2 Group By reportreq to allow for further descisions:
SELECT reportid, reportreq, Sum(batchprintcopies) AS SumOfCopies
FROM All_Reports
GROUP BY reportid, reporteeq
HAVING Sum(batchprintcopies)>0
3 Include reports where reportreq is null:
SELECT reportid, SUM(batchprintcopies) FROM All_Reports
WHERE reportreq <>"N" Or reportreq Is Null
GROUP BY reportid
HAVING Sum(batchprintcopies)>0
It is unlikely, but not impossible that a field (column) contains a zero-length string. I reckon they should be avoided.
SELECT reportid FROM All_Reports
WHERE reportreq IS NULL OR reportreq = "";
1) This query works by taking each report ID and looking for a row where someone has not marked it as "not required" (with the assumption that 'n', and 'N' are the only ways to indicate that). If it finds any rows for that report ID that are still required.
SELECT DISTINCT report_id FROM table_name AS outer
WHERE NOT EXISTS
(SELECT report_id FROM table_name
WHERE report_req NOT IN ("n","N")
AND report_id=outer.report_id);
2) This query just adds up the values of batchprintcopy on a per-report_id basis (where the report is required, same assumption as above).
SELECT report_id, SUM(batchprintcopy) FROM table_name
WHERE report_req NOT IN ("n","N")
AND batchprintcopy > 0
GROUP BY report_id;
3)
SELECT report_id FROM table_name
WHERE report_req IS NULL OR report_req = "";