I have a table I created to use as the source for the of dropdowns of a form. The goal is to have only what possible options are available for the Department code based on who the owner is. I got the scrap owner to display correctly but unfortunately I have not been able for the department code to show up. No options are able to pop up. This is what my code looks like:
Select DEPT_CODE, DEPT_CODE as Value From Degrade_Robots
WHERE SO_NAME = :P7_SCRAP_OWNER
group by DEPT_CODE
order by DEPT_CODE
My table is set up like:
You aren't aggregating anything; don't use group by but distinct.
select distinct
dept_code as display_value,
dept_code as return_value
from degrade_robots
where so_name = :P7_SCRAP_OWNER
order by dept_code;
As you don't see anything in the list, I presume that's because you forgot to mention P7_SCRAP_OWNER item in Select List's LoV Parent Item(s) property.
Related
On a form called opportunity I have a combobox called cmbCompanyName to select a company name from a table called Company. This is the first part of my cascade.
The cmbCompanyName has three columns.
Col 0 is the CompanyID, which is hidden.
Col 1 is the CompanayName, which is populated to the form
Col 2 is the CompanyCity, which is populated using a different part of the form using the control =[cmbCompanyName].[Column](2)
All of this works correctly.
The second part of my cascade cmbPoCLastName looks at another table called Contacts and should take the CompanyName from cmbCompanyName to filter my choices.
cmbPoCLastName uses the following query
SELECT Contacts.Company, Contacts.[Last Name], Contacts.[First Name], Contacts.[E-mail Address], Contacts.[Business Phone]
FROM Contacts
WHERE (((Contacts.Company)=[Forms]![Opportunity]![cmbCompanyName]));
To support my cascasde, cmbCompanyName requeries cmbPoCLastName upon update.
Private Sub cmbCompanyName_AfterUpdate()
cmbPoCLastName.Requery
End Sub
All of this result in nothing showing up in the second part of my cascade.
I believe the issue is cmbPoCLastName is filtered by the hidden CompanyID. I cannot figure out how to force this query to look at the company name vs. the ID number.
Thanks.
Based on the first comment made by #June7, I reworked my tables to use CompanyID to related them to one another. I had previously used CompanyID in some tables and CompanyName in others.
I need to export my SSRS report to csv format. Issue I am facing is that few column header names change with country code (parameter) and I want to show the same name in my exported csv. I have gone through other related questions and topic, specifically this one. It suggested that there is a work around by setting data value to null. I have tried this by adding columns and hiding these based on country code, along with setting data value to null for that dataset field. But it did not work. I still get the hidden column in my export, with no values in it.
Can someone confirm that this workaround works or is there any other way apart from creating different reports for each country?
UPDATE: (added report screenshot and description for clarification)
Based on apporoach I have taken,
I need to only show Column 'Town' for Country A and only 'Suburb' for Country B. This is easily done by hiding columns based on Country Parameter( and works fine for EXCEL export), but when exported to CSV, both columns are exported.
UPDATE 2
Found this link which is similar to what I have been trying to figure out and looks like there is no solution which can be achieved using only one report.
According to this post
MSDN Social: Hide CSV columns conditionally in SSRS report
The XML and CSV renderers use the DataElementOutput property to
control visibility. We can select which item we want to hide in the
report, and set the “DataElementOutput” property with value “NoOutput”
to work around the issue.
Alternatively, we can add below expression to control the item’s
visibility. Please refer to the expression below:
=IIF(Globals!RenderFormat.Name="CSV",True,False)
This, incidentally, is the second answer in the thread that you posted. That answer links to the following article which explains how to do exactly what you need
Hide/Show Items Dependant On Export Format
UPDATE
It appears that you cannot programmatically set DataElementOutput for CSVs. However, according to this post SSRS - Programatically controlling the DataElementOutput property
in RS 2005 / 2008, you should be able to get the desired effect by adding a filter on the tablix directly (in addition to the visibility condition):
Filter expression: =(Parameters!DataPeriod.Value = "DAY")
Filter operator: =
Filter value: =true
Thereby, for the cases where the tablix is not visible, you are also filtering out all the data.
You may be able to show/hide country specific columns this way instead.
My approach would be to do this in SQL. I'm not sure how you determine which Countries require the town to be returned and which require the suburb to be returned but here's a couple of approaches that hopefully cover your scenario.
In either case, the idea is to return the town/suburb data in the same column and then an additional column that will contain a a caption that we can use as the column header.
a. Only one of either the town or suburb column in your table is populated. In this case it's pretty simple.
SELECT
Country
, ISNULL(TownOrCity, StreetSuburb) AS TownSuburb
, CASE WHEN TownOrCity IS NULL THEN 'Street-Suburb' ELSE 'Town-City' END AS Caption
FROM myTable
b. You know upfront which Countries require what and you can pass a parameter in to get the correct column. In this example we'll use a parameter called #TS and pass in either a T or and S
SELECT
Country
, CASE #TS WHEN 'T' THEN TownOrCity ELSE StreetSuburb END as TownSuburb
, CASE #TS WHEN 'T' THEN 'Town-City' ELSE 'Street-Suburb' END AS Caption
FROM myTable
Whichever approach we take you will end up with a simple table
Country TownSuburb Caption
Testland TownA Town
Testland TownB Town
Testland TownC Town
In you report, you don;t need to do anything except make the town/suburb column caption an expression something like =FIRST(Fields!Caption.Value)
That's it, the report is now nice and simple and should export without any issues.
UPDATE to method:
--
-- Dump data into a temp table
--
SELECT
Country
, CASE #TS WHEN 'T' THEN TownOrCity ELSE StreetSuburb END as TownSuburb
INTO #t
FROM myTable
--
--rename the column
--
DECLARE #NewColumnname sysname = CASE #TS WHEN 'T' THEN N'Town-City' ELSE N'Street-Suburb' END
EXECUTE tempdb..sp_rename N'tempdb..#t.[TownSuburb]', #NewColumnname, 'COLUMN'
--
-- finally get the result
--
SELECT * FROM #t
I am at my wits end here and have tried every code combination imaginable ( and what I can download) to get those elusive cascading combo boxes to work.
I have 6 of them and this is for a shipping database.
User has to select REGION then COUNTRY and then PORT.
That is both for origin and destination, so 6 in total.
I can get this to work only under the following conditions;
The Form is unbound, and have to use VBA/SQL to insert the selected values into the table.
Once the values are in the table, it is the ID's not the actual value (example "Asia").
I really need the form bound to the shipments table and combo boxes Control Source set to that particular Field.
I have a sinking feeling I am barking up the wrong tree and it cannot be done.
Any suggestions here?
cmbRegions.RowSource = SELECT ID, Region FROM tblRegions
cmbCountry.RowSource = SELECT ID, Country FROM tblCountries WHERE RegionID = frmForm!cmbRegion
cmbPort.RowSource = SELECT ID, Port FROM tblPorts WHERE PortID = frmForm!cmbPort
In the AfterUpdate event of `cmbRegions':
cmbCountry.Requery
In the AfterUpdate event of `cmbCountry':
cmbPort.Requery
I'm trying to follow Microsoft's example on how to add an "All" option to a ComboBox in Microsoft Access, but their article does not do an adequate job of providing guidance, aside from specifying the code.
What I'm trying to do is build a form that allows a user to select an option from a ComboBox (the options are generated from records in a table), and then build a report filtered based on the user's selected option. The ComboBox consists of 2 columns: the primary key/ID of the records and their displayable names.
I can't understand the VBA code Microsoft provides enough to figure out what is going on, but I would like the "All" option in my ComboBox to either have a blank primary key/ID, or one that = 0. That isn't the case, as selecting the "All" option when using the form results in the error message "The value you entered isn't valid for this field". This leads me to believe that the "All" text is getting filled into the primary key/ID column instead of the display column. The example instructs me to assign the display column number as the "Tag" property of the ComboBox - and in this case, my display column number is 2. However, this (and pretty much any other value I add) results in the aforementioned error message.
Any idea if Microsoft's example is even applicable to my case, or do I need to adjust their code somehow?
Check the Control Source property of your combo box. Sounds like it may be bound to a field in the form's record source. If you make it an unbound control (nothing in the Control Source property) you should be able to select any item from the combo's Row Source without Access complaining at you.
Say your combo's Row Source is a query like this:
SELECT id, disp_name
FROM YourTable
ORDER BY disp_name;
You can add an "all" row with a UNION query:
SELECT id, disp_name
FROM YourTable
UNION ALL
SELECT TOP 1 0, "**ALL**"
FROM AnyTable
ORDER BY disp_name;
AnyTable can be just that. If you happen to have a table which contains only a single row, use that one ... and you wouldn't even need the TOP 1 part. Just try not to use some ReallyBigTable as AnyTable.
Edit: Actually some ReallyBigTable would be fine if it has a primary key or other unique field which you can use in a WHERE clause to retrieve a single row:
SELECT id, disp_name
FROM YourTable
UNION ALL
SELECT 0, "**ALL**"
FROM ReallyBigTable
WHERE pk_field = 1
ORDER BY disp_name;
UNION ALL will return all combined rows. If you have any duplicate rows, you can thin them out by using just UNION instead of UNION ALL.
I have a table Project.
It has the following column: Project ID, projectName, UpdateTime
The data in the table is as follows:
Project ID projectName UpdateTime
1 abc 12-2-2009 01:10:00
1 abc 12-2-2009 04:18:00
2 xyz 17-7-2009 08:45:00
2 xyz 17-7-2009 12:21:00
i want the result set to display the latest update project information based on the update time.
for the above example , it should display
Project ID projectName UpdateTime
2 xyz 17-7-2009 12:21:00
1 abc 12-2-2009 04:18:00
This ought to do the job (as edited to reflect the information #Remou pointed out that I failed to note in your original question):
SELECT [Project ID], ProjectName, Max(UpdateTime)
FROM Project
GROUP BY [Project ID], ProjectName
ORDER BY Max(UpdateTime) DESC
If that doesn't do it, either I've made a mistake, or there's other information not included in your question.
SELECT P.[Project ID]
, P.projectName
, Max(P.UpdateTime) AS [Latest Update Time]
FROM Project AS P
GROUP BY P.[Project ID]
, P.projectName
ORDER BY Max(P.UpdateTime) DESC;
I have an answer which uses the graphical interface of a query which may be easy for you to implement. It is presumed that all 3 fields are contained in a single table. Create a new query by clicking "CREATE" and thereafter "Query Design". Right click in the upper section of the graphical interface that opens and click on "Show Table" Select the table that contains these three fields and double click on each field, one at a time so that it appears in the lower section. If you have an auto-number field please ensure that you do not include it in the lower section since this will cause all the table records to display. Any other additional field included in the query could have the same undesired result. Next, on your ribbon click "DESIGN" and after that click on the "Totals" icon. Focus attention on your "UpdateTime" field in the lower section. Change "Group By" to "Max" by clicking into that field and selecting from the drop-down list. To not make ay changes to the other two fields. Save the query and open it in Datasheet view (Do this by clicking "HOME", "View", "Datasheet View"
You should get the results you required. Please let me know whether this has now worked for you.
Ps. Spelling errors in the project name will also give you inaccurate results. To reduce the likelihood of this possible problem have your users to select project names from a combo-box that that has a drop-down list of project names. It is also possible to devise a means whereby the Project name is auto entered when a user selects a Project ID from a drop-down list.
I am not sure why everyone seems to want to group the projects. The question simply seems to ask to display the results in descending order of UpdateTime
SELECT * FROM Project
ORDER BY UpdateTime DESC
I also notice however, that in his example, the results that he anticipates has the records grouped by Project ID and Project Name, in which case the answer provided by #David-W-Fenton must be sufficient.
In Conclusion, he should have asked his question more clearly.