I have a cascading parameter setup for my report so that once I select a Client Number, it displays the Matter Numbers. I don't have a value for the client number set because we often search by the client number so it's easier to manually input that number in. The cascading parameter part works in that I type in a client number and received a drop down list of matters. However, when I click run report, it displays the details for ALL of the matters and not for just the one single matter I pick.
The main dataset has both parameters in the SQL as IN (#ClientNumber) AND IN (#MatterNumber). I've tried adding them as filters in the dataset properties, but that doesn't seem to do it either.
So the cascading parameters work in that I choose one and the next field ungreys and allows me to pick my next parameter, but then it just displays all data as if I hadn't picked a second parameter.
Any thoughts? I'm happy to provide whatever is needed.
--Including my query per request. I am using Microsoft SQL.
SELECT
HBM_MATTER.CLIENT_CODE,
HBM_MATTER.MATTER_CODE,
HBM_NAME.NAME,
HBM_MATTER.LONG_MATT_NAME,
HBM_PERSNL_ORG.EMPLOYEE_NAME AS Originator,
HBM_PERSNL_BILL.EMPLOYEE_NAME AS Billing,
HBM_PERSNL_RSP.EMPLOYEE_NAME AS Responsible,
HBM_CLIENT.OPEN_DATE AS [Client Open Date],
HBM_MATTER.MATTER_UNO,
HBM_CLIENT.CLIENT_UNO,
HBM_MATTER.MATT_TYPE_CODE AS [Area of Law Code],
HBL_MATT_TYPE.MATT_TYPE_DESC AS [Area of Law Description],
HBM_MATTER.OFFC AS [Office Code],
HBL_OFFICE.OFFC_DESC AS [Office Description],
HBM_MATTER.DEPT AS [Department Code],
HBL_DEPT.DEPT_NAME AS [Department Name],
HBM_MATTER.PROF AS [Practice Team Code],
HBL_PROF_CTR.PROF_CTR_DESC AS [Practice Team Description],
HBM_MATTER.STATUS_CODE AS [Status Code],
HBL_STATUS_MATT.STATUS_DESC AS [Status Description],
HBM_MATTER.OPEN_DATE AS [Matter Open Date],
HBM_MATTER.CLOSE_DATE AS [Matter Close Date],
TBM_MATTER.LAST_BILL_DATE AS [Matter Last Billed Date],
HBM_PERSNL_TIME.EMPLOYEE_NAME AS Timekeeper,
TBM_CLMAT_PART_BILL.EFF_DATE
FROM
HBM_MATTER INNER JOIN TBM_CLMAT_PART AS TBM_CLMAT_PART_ORG ON HBM_MATTER.MATTER_UNO = TBM_CLMAT_PART_ORG.MATTER_UNO INNER JOIN
TBM_CLMAT_PART AS TBM_CLMAT_PART_BILL ON HBM_MATTER.MATTER_UNO = TBM_CLMAT_PART_BILL.MATTER_UNO INNER JOIN
HBM_CLIENT ON HBM_MATTER.CLIENT_UNO = HBM_CLIENT.CLIENT_UNO INNER JOIN
HBM_PERSNL AS HBM_PERSNL_ORG ON TBM_CLMAT_PART_ORG.EMPL_UNO = HBM_PERSNL_ORG.EMPL_UNO INNER JOIN
HBM_PERSNL AS HBM_PERSNL_BILL ON TBM_CLMAT_PART_BILL.EMPL_UNO = HBM_PERSNL_BILL.EMPL_UNO INNER JOIN
HBM_PERSNL AS HBM_PERSNL_RSP ON HBM_MATTER.RESP_EMPL_UNO = HBM_PERSNL_RSP.EMPL_UNO INNER JOIN
HBM_NAME ON HBM_CLIENT.NAME_UNO = HBM_NAME.NAME_UNO LEFT OUTER JOIN
HBL_MATT_TYPE ON HBM_MATTER.MATT_TYPE_CODE = HBL_MATT_TYPE.MATT_TYPE_CODE INNER JOIN HBL_OFFICE ON HBM_MATTER.OFFC = HBL_OFFICE.OFFC_CODE INNER JOIN
HBL_DEPT ON HBM_MATTER.DEPT = HBL_DEPT.DEPT_CODE INNER JOIN
HBL_PROF_CTR ON HBM_MATTER.PROF = HBL_PROF_CTR.PROF_CTR_CODE LEFT OUTER JOIN
HBL_STATUS_MATT ON HBM_MATTER.STATUS_CODE = HBL_STATUS_MATT.STATUS_CODE INNER JOIN TAT_TIME ON HBM_MATTER.MATTER_UNO = TAT_TIME.MATTER_UNO INNER JOIN
HBM_PERSNL AS HBM_PERSNL_TIME ON TAT_TIME.TK_EMPL_UNO = HBM_PERSNL_TIME.EMPL_UNO INNER JOIN
TBM_MATTER ON HBM_MATTER.MATTER_UNO = TBM_MATTER.MATTER_UNO
GROUP BY
HBM_MATTER.CLIENT_CODE, HBM_MATTER.MATTER_CODE, HBM_NAME.NAME, HBM_MATTER.LONG_MATT_NAME, HBM_PERSNL_ORG.EMPLOYEE_NAME, HBM_PERSNL_BILL.EMPLOYEE_NAME, HBM_PERSNL_RSP.EMPLOYEE_NAME, HBM_CLIENT.OPEN_DATE, HBM_MATTER.MATTER_UNO, HBM_CLIENT.CLIENT_UNO, HBM_MATTER.MATT_TYPE_CODE, HBL_MATT_TYPE.MATT_TYPE_DESC, HBM_MATTER.OFFC, HBL_OFFICE.OFFC_DESC, HBM_MATTER.DEPT, HBL_DEPT.DEPT_NAME, HBM_MATTER.PROF, HBL_PROF_CTR.PROF_CTR_DESC, HBM_MATTER.STATUS_CODE, HBL_STATUS_MATT.STATUS_DESC, HBM_MATTER.OPEN_DATE, HBM_MATTER.CLOSE_DATE, TBM_MATTER.LAST_BILL_DATE, HBM_PERSNL_TIME.EMPLOYEE_NAME, TBM_CLMAT_PART_ORG.EFF_DATE, TBM_CLMAT_PART_ORG.PERCENTAGE, TBM_CLMAT_PART_BILL.EFF_DATE
HAVING
(HBM_MATTER.CLIENT_CODE IN (#ClientNumber)) AND (HBM_MATTER.MATTER_CODE IN (#MatterNumber))
This is a known bug in SSRS.
The only way I have found as a workaround is to create a hidden multi-select parameter that is based on the value selected in the first parameter, and on which the second parameter takes it's values from.
This solution is messy and confusing to any future maintainers if your documentation is not detailed and available, but at times inescapable.
I would recommend trying to find a way to have your selection criteria without the use of these cascading parameters.
Related
Prompting for user input parameters in an Access query is fairly straight forward. Go to design view and under criteria, just put [Your Text:] -- and when the query runs the user is prompted for the field criteria.
Unfortunately when I try this with my Inner Joined Crosstab query I get the error:
The Microsoft Access engine does not recognize the '[Your Text:]' as a
valid field name or expression.
I know the inner join crosstab still allows for criteria, as hardcorded criterion works.
To give you a better idea of what I'm looking at, here is the SQL code.
DOESN'T WORK:
SELECT *
FROM ([CrossTabQ1]
INNER JOIN [CrossTabQ2] ON [CrossTabQ1].[Month] = [CrossTabQ2].[Month])
INNER JOIN [Query3] ON [CrossTabQ1].[Month] = [Query3].[Month]
WHERE ((([CrossTabQ1].[Month])= [Enter Month, in YYYY-MM Format:]))
ORDER BY [CrossTabQ1].[Month];
DOES WORK:
WHERE ((([CrossTabQ1].[Month])="2015-12"))
ORDER BY [CrossTabQ1].[Month];
Any tips regarding why I'm getting this error and how I can accept user input criterion would be greatly appreciated!
Try:
PARAMETERS Enter_Month Text ( 255 );
SELECT *
FROM ([CrossTabQ1]
INNER JOIN [CrossTabQ2] ON [CrossTabQ1].[Month] = [CrossTabQ2].[Month])
INNER JOIN [Query3] ON [CrossTabQ1].[Month] = [Query3].[Month]
WHERE ((([CrossTabQ1].[Month])=[Enter_Month]))
ORDER BY [CrossTabQ1].[Month];
I'm using Access 2010 and create a string filter on the fly by pulling information from the user via various controls on a subform. I then use the filter in one of two ways:
I set the recordsource of another subform in datasheet view
Forms![frmCentral]![TrainingEventsSubform].Form.RecordSource =
gstrTrainingEventsFormFilter
Or I use it as the query parameter of openreport
DoCmd.OpenReport "rptTrainingEvents", acViewPreview, gstrTrainingEventsFormFilter
I don't understand why, but the query string works fine when setting the recordsource, but the exact same string will result in an Enter Parameter Value box appearing when issuing the openreport command. Further, the query works perfectly if I paste it into the report's recordsource parameter.
As an example, here's a string that's built:
SELECT TrainingEvents.StartDate, TrainingEvents.EndDate, ClassList.ClassNumber, [Users].[FirstName] & ' ' & [Users].[LastName] AS Trainer, TrainingLocations.TrainingLocationName, EventVenues.EventVenueName, TrainingEventStatus.TrainingEventStatus, TrainingEvents.TrainingEventID
FROM Users INNER JOIN (TrainingLocations INNER JOIN (TrainingEventStatus INNER JOIN (EventVenues INNER JOIN (ClassList INNER JOIN TrainingEvents ON ClassList.ClassID = TrainingEvents.ClassID) ON EventVenues.EventVenueID = TrainingEvents.EventVenueID) ON TrainingEventStatus.TrainingEventStatusID = TrainingEvents.EventStatusID) ON TrainingLocations.TrainingLocationID = TrainingEvents.TrainingLocationID) ON Users.UserID = TrainingEvents.TrainerID
WHERE (TrainingEvents.StartDate >= #1/1/2014#) AND (TrainingEvents.EndDate <= #12/31/2014#) AND (Users.UserID = 10)
ORDER BY TrainingEvents.StartDate;
The Enter Parameter Value box appears with Users.UserID.
It's obviously something with userid, but for the life of me I can't understand what!
Any suggestions?
http://sqlfiddle.com/#!3/3ec1f/119
Here's my fiddle...I want the result to look like this but the query I'm using doesn't do that:
My problem with the query is that I can't seem to exclude "The Kingdom of the Crystal Skull" using the exclusion_flag condition. I also don't know why it seems that Contract 3 (Raiders of the Lost Arc) is not showing up either. I have been toiling with this for hours and have no idea what the problem is. I tried looking into subqueries, but I'm not sure that's the solution...
There's a couple of questions/issues there so I'll try to address them individually.
1) You can't exclude "The Kingdom of the Crystal Skull" using the exclusion_flag because contract_sid 7 and 8 both refer to product_list_sid 3 which includes "The Kingdom of the Crystal Skull" - you would need to create a separate product_list_sid if you wanted a contract which excluded it.
2) "Raiders of the Lost Arc" (contract_sid 3) isn't showing up because it's a "single product" contract, and your query only joins from scope to product_list_join using product_list_id - contract_sid 3 is in the product_sid column so you need a separate join to cater for contracts that use product_sid instead of product_list_sid (I assume that a contract can't use both). This is a pretty dodgy schema design but here's a query that solves that issue. Notice the use of LEFT OUTER JOIN to indicate that the table being joined to might not contain any rows (for example when scope.product_list_sid is NULL but scope.product_sid is not).
SELECT s.contract_sid,
c.contract_description,
ISNULL(p.product_description, p2.product_description) AS product_description
FROM scope s
JOIN contracts c ON (c.contract_sid = s.contract_sid)
LEFT OUTER JOIN
product_list_join plj ON (plj.product_list_sid = s.product_list_sid)
LEFT OUTER JOIN
products p ON (p.product_sid = plj.product_sid)
LEFT OUTER JOIN
products p2 ON (p2.product_sid = s.product_sid)
WHERE s.exclusion_flag = 'N'
ORDER BY s.contract_sid;
Here's the SQLFiddle for my solution: http://sqlfiddle.com/#!3/fc62e/10
Edit: After posting this I realised what you're actually trying to do - the scope table not only provides the details of contracts but also provides specific products to exclude from contracts. Again, this is bad schema design and there should be a separate scope_exclusions table or something, but here's a query that does that and excludes "The Kingdom of the Crystal Skull" as requested:
SELECT inner_query.contract_description,
inner_query.product_description
FROM (
SELECT s.contract_sid,
c.contract_description,
ISNULL(p.product_sid, p2.product_sid) AS product_sid,
ISNULL(p.product_description, p2.product_description) AS product_description
FROM scope s
JOIN contracts c ON (c.contract_sid = s.contract_sid)
LEFT OUTER JOIN
product_list_join plj ON (plj.product_list_sid = s.product_list_sid)
LEFT OUTER JOIN
products p ON (p.product_sid = plj.product_sid)
LEFT OUTER JOIN
products p2 ON (p2.product_sid = s.product_sid)
WHERE s.exclusion_flag = 'N'
) inner_query
WHERE NOT EXISTS ( SELECT 1
FROM scope
WHERE exclusion_flag = 'Y'
AND contract_sid = inner_query.contract_sid
AND product_sid = inner_query.product_sid )
ORDER BY inner_query.contract_description;
SQL Fiddle: http://sqlfiddle.com/#!3/fc62e/14
Alright, I am attempting to use a basic left() function with a MS Access query, in order to create an inner join between two tables. The two columns that will be joined contain the first 3 character of a given street address.
I have attempted to use the function as shown:
I simply want to take the first 3 characters (from the left obviously) of this column, and join it to the "Left 3 of adress" column in my Branch Management sheet. Every time I attempt to run this query however, I get a syntax error. The left function is pretty straightforward in almost every language/RDBMS, what am I doing wrong?
EDIT: here is a screen shot of the error:
The error is wonderfully vague.
You left out a close parenthesis. Change this ...
ON ([Branch Mgmt].[Left 3 of address] = left([SalesPage Offices w/CRD].ADDRESS_LINE_1,3)
to this ...
ON ([Branch Mgmt].[Left 3 of address] = left([SalesPage Offices w/CRD].ADDRESS_LINE_1,3))
I don't think you can use the LEFT() function in your join statement. Instead run a sub query to get the field you want and then link them together. Something like the following:
SELECT M.TRADE_FIRM, M.POSTAL_CODE_1, M.ADDRESS_LINE_1,
M.OFFICE_ID, M.STATE_PROVINCE, M.CITY, B.*
FROM
(
SELECT S.*, LEFT(S.ADDRESS_LINE_1, 3) AS Left3Addr
FROM [SalesPage Offices w/CRD] AS S
) AS M
INNER JOIN [Branch Mgmt] AS B ON B.[Left 3 of address] = M.Left3Addr
AND B.State = M.State
AND B.City = M.City
WHERE M.TRADE_FIRM = 'WHATEVER'
How do I ensure that I pick up the right number of records when filtering for dates within an Access Query:
SELECT ID, REF, SalesDate, DCount("ID","tblRecords"," Ref='" & [Ref] & "' AND [SalesDate]=#" & format([SalesDate],"yyyy/mm/dd") & "#") as EXPR1 from tblCurrent
It picks up the date ok if it cannot be misconstrued such as 28-04-12, but if it is 04-06-12 it doesn't pick it up as it's assuming it's the wrong way around.
Note that this query is not created on the fly or generated from a form etc...
I either use yyyy/mm/dd for dates in VBA:
#" & Format([SalesDate],"yyyy/mm/dd") & "#"
Or parameters, for building queries.
EDIT re additional information
Seeing you are using SQL server, I suggest you use a derived table, which you may find faster, for example:
SELECT dbo_Table_1.ADate, ACount FROM dbo_Table_1
LEFT JOIN (SELECT a.ADate,Count(*) As ACount
FROM dbo_Table_1 As a GROUP BY a.ADate) b
ON dbo_Table_1.Adate=b.ADate
EDIT re discussion
SELECT * FROM dbo_vwRecordsCurrent As t
LEFT JOIN (
SELECT a.OpptyIncentiveModifiedDate, a.DataSetID, Count(*) AS ACount
FROM dbo_vwRecordsHistorical AS a
WHERE a.OpportunityIgnored = True
GROUP BY a.OpptyIncentiveModifiedDate, a.DataSetID) AS h
ON t.OpptyIncentiveModifiedDate = h.OpptyIncentiveModifiedDate
AND t.DataSetID = h.DataSetID
I have aliased your tables as the names are very long, so to me, it is more readable to use aliases on the outer sql. They are essential in the inner sql. It is not a good idea to alias a derived table with the name of an existing table.