oracle Report Builder - Using Case in a query produces symbol? - sql

I am using Oracle Report builder and I've noticed when I use the case function
Case Column
when this then that
when this then that
else this
end
in a query it produces this symbol-
Symbol
. This causes issues with the final output where duplicates occur.
Any feedback would be appreciated.

You're talking about an icon which looks like a "C/D", next to query name, right? If so, it represents a non-linkable query.
Documentation (2.3.5 About non-linkable queries) says:
A non-linkable query is a detail query that contains column objects
that prevent the query from being linked to via a column-to-column
link (when you create a column-to-column link, Reports Builder adds a
WHERE clause to your query). If you attempt to create such a link, a
message dialog box displays, which prompts you to choose whether to
create a group-to-group query (using the parent groups), or to cancel
the operation. A non-linkable query displays a non-linkable icon in
its title bar (C/D).
Instead, you can create a group-to-group link (when you create a
group-to-group link, Reports Builder does not add a WHERE clause to
your query) between the two queries and add a WHERE clause to the
child query’s SELECT statement, using a bind variable to reference the
parent column.
For example, suppose you want to create a column-to-column link
between the ADDRESS.STREET column in your child query and the LOC1
column in your parent query. You can create a group-to-group link, and
then modify the child query SQL statement to say: SELECT * FROM EMP E
WHERE E.ADDRESS.STREET = :LOC1
I'm not sure it is related to your problems with "duplicates". The simplest way to get rid of them is to use DISTINCT keyword, e.g. select distinct this, that from ... but the actual solution might differ, depending on what you really have & do.

Related

Drop-Down Box in a Selection Query - MS ACCESS

I'm working on a selection query in my Access database. in one of my columns I wanted to have a drop-down list with selected data. Unfortunately nothing is showing, and I'm thinking about two Problems that can be responsible for this :
The selection wont show up until I link my query to a table where I can modify and select from the drop down list.
I made a mistake in developing but can't find anything about that mistake
Here is the details of whats going on :
What I want
This image is just the result of my query not linked to a table
What I have
Is an actual drop down list without any data in it (still talking about the result of the query not linked to a table in which modification can be made directly)
Here is What I did
Added the queries and tables I'm working on and then =>
Selected the column I wanted it to be a drop-down list and then added the following query after changing it to a drop down list
SELECT [SALARIE_nom] & " " & [SALARIE_prenom]
FROM (T_STATUT_EMPLOI INNER JOIN T_SALARIE_EMPLOI ON T_STATUT_EMPLOI.STATUT_EMPLOI_id = T_SALARIE_EMPLOI.SALARIE_EMPLOI_statut_id) LEFT JOIN R_Select_Salarie ON T_SALARIE_EMPLOI.SALARIE_EMPLOI_salarie_nni = R_Select_Salarie.SALARIE_NNI
WHERE (((T_STATUT_EMPLOI.STATUT_EMPLOI_statut) Like "*validé*") AND ((T_SALARIE_EMPLOI.SALARIE_EMPLOI_Entreprise) Like "*RTE*"));
if I run the sql query on it's own, it gives me the results I want but when trying to see this result in the final table (result table of my query) I got the blank drop-down list.
here is the result I get from executing the query alone :
So I think it's working.
Thank you in advance for reading my explanation and for your comments
I think that everything was fine, and that it was just a bug. After linking my query to a form I started seing the data in the drop-down list in both the form and query.
But I still Have one small issue which is :
Not being able to modify or choose from my drop-down List.
What I did
I created my form using Forms Assistant in access and then I chosed as data source my query. But I can't modify my form or anything could please suggest something to me.
Thank you !

Count records from another table to include in the results of a bound table

I am using Visual Studio and have an Access database with a couple of tables that are related. They are using default drag/drop binding using WinForms to the dataset which was automatically generated as well.
I want the parent table to include a column with the count of the number of related records with that ID in the results. The tables look like this if it matters:
I added an additional query to the table adapter (as you can see from the screenshot) that does what it needs to do (without including the linked ID's) thinking that was how to do it. Am I at least on the right track? The query looks like this:
SELECT COUNT(*) AS WorkerCount
FROM (tblJobLaborTech INNER JOIN tblJobLabor ON tblJobLaborTech.JobLaborID = tblJobLabor.JobLaborID)
WHERE (tblJobLabor.JobLaborID = 494)
And of course I need to change 494 to something variable which will match the corresponding record when it runs, but
WHERE (tblJobLabor.JobLaborID = tblJobLaborTech.tblJobLaborTechID)
doesnt seem to preview at all (no value given for parameter)
so i also tried
WHERE (tblJobLabor.JobLaborID = #JLID)
which also doesnt preview.
But that's only the start of the problem. Let's say I can get that part working, how do I get the result of that Scalar query to run for each record in the calling query and return in the dataset as if it were another field in that table?
You don't need to do this using the DB. A datatable can count the records present along a child relation
In your tblJobLabor add another datacolumn (right click, add>>column) and set its Expression property to:
Count(Child(XXX).JobLaborID)
Replace XXX with the name of this DataRelation I've highlighted:
More information can be found by looking at the fairly lengthy documentation on DataColumn.Expression at https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8

Choose AS400 query records directly from Excel

I've been searching the internet for hours trying to figure out if the following is even possible:
To choose the AS400 query records directly from Excel.
I haven't found any solution or description of how this could be achieved, which makes me guess that it's simply not possible. However, I haven't seen anyone confirm that it is impossible.
So my question is: Is this possible? And if it is, could you point me in the right direction in order for me to start learning how to do it?
I know its possible to run a query from Excel, and then adding parameters via SQL statements, but in my case, this presents several problems that could be avoided by choosing the records before the query is executed.
Example:
I have a query with a column (lets call it ColVal) that can hold the values 1 and/or 2. In the AS400 program under the menu "Work with queries" and then "Choose records" I can specify which records the query should contain when it has run based on the value in ColVal. This means i can get three different situations (A, B and C) when i run the query:
A) The query only contains records where the value in ColVal is 1
B) The query only contains records where the value in ColVal is 2
C) The query contains records where the value in ColVal is either 1 or 2
The goal is to be able to choose which situation I want from Excel in order to circumvent opening and using the AS400 program.
However, using situation C and then editing the query in Excel with an SQL statement to mimic situation A or B is not an option, as this means the query still contains undesired records.
This whole thing boils down to the following: Is it even possible to run the query from Excel essentially changing the data it contains and not just outputting it to excel? If this is possible, is it then possible to pass a parameter to the AS400 system and use it to create situation A, B or C?
I hope this example makes sense.
Edit - New example
Say i have different customers A and B. I can open the AS400 program and run a query in which i have specified that I only want data on customer A. I can then open Excel and use filters (as Hambone described) on the query to determine which records I want to output. However, if I want to work with data from customer B, I have to open the AS400 again and run the query with different parameters. I would like to be able to "change" my dataset from customer A to B from Excel, without having to include both in my recordset and then filter out one of them.
I imagined this is doable if you could pass a parameter to the AS400. The AS400 then runs the query using this parameter as the criteria for which records should be stored in the query. This means that if the parameter is Customer B, then there is no way to acces data from customer A, without running the query through AS400 again.
Any ideas are greatly appreciated :)
Follow up to my comment, here is a quick primer on how to run an ODBC query directly in MS Excel using Microsoft Query. This is very different than Power Query, which you referenced, in that MS Query is standard with Excel -- it's not a plug-in. This is relevant because it means everyone has it. If you are deploying a solution to others, that's an important consideration.
To start an MS Query in Excel, go to the data tab, select "From Other Sources" -> "Microsoft Query."
A list of your ODBC connections will come up. Pick the one that you want and select "OK."
It may or may not ask you for a login (depending on which ODBC connection you use and how its configured).
The next part is important. MS Query is going to try to have you use its builder to create the query. If you have the SQL, skip this part. It's horrible. Click "Cancel" on the query wizard, and then click the "SQL" button to enter your own SQL. If you can, make sure the result set is small (like use where 1 = 2 in the query).
When MS Query returns results, click the button next to the SQL Button to have it return the results to the spreadsheet. It looks like a little door.
From here, any time you want to refresh the query, you can simply right-click the data table in Excel and select "refresh." Alternatively you can go to the data tab on the ribbon and select "Refresh."
By the way if you have linked pivot tables and charts, the "Refresh All" option will refresh those as well, in the correct order.
To edit your query at any time, right-click on the table in Excel, go to Table-External Data Properties:
Then Click on the Connection Properties icon (highlighted below)
Click on the second tab (Definition) and edit the SQL Directly.
Parameters can be declared simply by inserting a bare "?" in place of your literal.
In other words, if your query looks like this:
select *
from users
where user_id = 'hambone'
Just change it to:
select *
from users
where user_id = ?
Excel will prompt you for a user id before it runs the query. From here, you also have the option of putting the parameter value in a cell within the spreadsheet and having the query read it from there. You'll see these when you right-click the table and go to the "Parameters" menu option.
Let me know if this helps or is unclear.
-- EDIT 7/23/2018 --
To follow up on your latest edit, it is possible to handle the scenario you describe, where you want to be able to filter on a value, or if none is given, then not have a filter. You see this a lot when you present multiple filter options to the user and you want a blank to mean "no filter," which is obviously counter to the way SQL works.
However, you can hack SQL to still make it work:
select * from activities
where
(activity = ? or ? is null) and
(energy = ? or ? is null)
In this example you have to declare four parameters instead of two, two for each.
You might also have to play with datatypes, depending on the RDBMS (for example for numerics you might have to say ? = 0 instead of ? is null or even ? = '' for text).
Here is a working example where a single filter was applied on the query above and you can clearly see the second one did not have an impact.
Yes it's possible. You need to use an ODBC driver to connect to the AS400 and retrieve the data. The driver and documentation are Here

Multiplying 2 value in database

I have a database. I created it with HeidiSQL. Its look like this.
I enter the value-1 and value-2.
Is there a way to enter a formula to Result column like " =Value-1 * Value-2 " ? I want my database to calculate the Result when I enter my values to other cells.
A trigger is one way to achieve automated column content.
A second one is a view, which you can create additionally to the table. That view could contain SQL which generates the result:
SELECT value1, value2, value1*value2 AS result
A third (more modern) alternative is adding a virtual column in your existing table. You can do that with HeidiSQL's table editor, like shown in the screenshot. Just add a new column with INT data type, and set its Virtuality to "VIRTUAL", and Expression to "value-1 * value-2". That's it.
I'm not familiar with HeidiSQL, but it appears to be a front end? What RDBMS are you using, for example SQL Server allows a computed column.
SQL
ALTER TABLE YourTable
ADD Result AS ([Value-1] * [Value-2])
Right click your database name in the folder structure, go to --> create new then -->Trigger
Then you can create a trigger that when entering data, will be activated on the entire column like this:
But you will need to know how to write the actual query and function. This requires basic knowledge that is generally generic and consistent of most all SQL languages.

SQL INSERT INTO with SELECT and INNER JOIN

I hope you can help me with this little problem. I am not quite sure of how to explain the situation to you, so I will just give it a try.
What I am trying to do is the following:
I want to insert some specific values and parameters (which I type in myself) into the table RFC_Risks, so basically every time I find a specific reason inside the table RCF_Risks, I want to write a new row that updates the priority of the RfC, every time that happens, the position shall be increased by 1.
My problem is now, that when I run this statement, I just get the SELECT part :-), not inserting is done, neither do I get a SQL statement error or anything like that. I just type in the parameters and then I get a SELECT Table thats all.
I'm using MS Access 2010 and I hope you can help me out with my "little" problem.
INSERT INTO RFC_Risks (RFC_No, RiskPos, Datum, Comments, RiskPrio, Reason)
SELECT RFC_Risks.RFC_No, (RFC_Risks.RiskPos +1) AS RiskPos, [Aktuelles Datum] AS Datum, [Kommentartext] AS Comments, [Neue Prio] AS RiskPrio, RFC_Risks.Reason
FROM RFC_Risks INNER JOIN Risk_Reasons ON RFC_Risks.Reason = Risk_Reasons.Reasontext
WHERE RFC_Risks.Reason = Risk_Reasons.Reasontext;
I can't spot anything about your SQL statement which would prevent it from executing and/or throw an error. (I think your WHERE clause is redundant, but that should not cause the db engine to reject it.) What method are you using to "run" it?
If you're using the Access query designer, and switch from Design View to Datasheet View, your query isn't actually executed ... Datasheet View will show you the rows which would be affected if the query were executed.
The situation is the same as if you were building a delete query in the query designer ... Datasheet View would show you which rows would be deleted if the query were executed, but switching to Datasheet View does not delete those rows.
To execute the query, click the icon which has a red exclamation point.
Try enclosing the subselect in parentheses.
You need to execute your query. If you only display it in Datasheet View, the SELECT Statement is executed and displayed to you as a kind of preview.
To really execute the query, when you are in design mode, you can click on the "Run" button (a red exclamation mark) in the toolbar. You can also double-click on the query in the database window.