I created a page to insert and modify data of an existing mysql- table.
But based on my requirements and the structure of the table I have to modify the sql for inserting data.
Because I am completly new on rapidclipse and java I need some hints/ examples how and where to modify this.
Looking all rapidclipse videos did not give the right hint.
I would like to insert three fields into a mysql-table
One of the fields I have to edit manualy.
The second field contains always the same value.
The third field contains a calculated value, which I have to fetch while runtime from the database.
As sql I would use following code:
INSERT INTO OKM_DB_METADATA_VALUE (DMV_TABLE, DMV_COL00, DMV_COL01)
VALUES ('T_supplier', (select * from (select max(cast(DMV_COL00 as
Integer)) +1 from OKM_DB_METADATA_VALUE as t2 where DMV_TABLE =
'T_supplier') as t3 ) , 'new suppliername');
The value for field DMV_Table will be always 'T_supplier'
The value for field DMV_COL00 is always the highest value in the col +1
The value for field DMV_COL01 will be always entered manually
(I am not able/ I don't want to modify/ use table form, -design and trigger, because it is a original table of OpenKM)
Thank you in advance!
best regards
OpaHeinz
Just a suggestion for sql code .. Your code could be refactored in a more SQL like code .. You could avoid the innner subquery .. and use a normal insert select
INSERT INTO OKM_DB_METADATA_VALUE (DMV_TABLE, DMV_COL00, DMV_COL01)
select 'T_supplier', max(cast(DMV_COL00 asInteger)) +1 , 'new suppliername'
from OKM_DB_METADATA_VALUE
where DMV_TABLE ='T_supplier'
The first step to solution
In the buttonClick event of save function
I set the value of DMV_Table field with:
... this.txtDmvTable.setValue("T_supplier");
The second step;
I created a view in the database wich delivers only the expected value:
`CREATE
OR REPLACE
VIEW `okmdb`.`V_suppliers_newID` AS
select
1 as "id",
max(cast(DMV_COL00 as Integer)) +1 as "newSupId"
from OKM_DB_METADATA_VALUE
where DMV_TABLE = 'T_supplier'; `
After that I created an entity in rapidclipse, read the value out of the view and assigned it to the other field DMV_COL00.
This was all.
Related
I unsuccessfully attempted to leverage Java's DerivedQueries but cannot accomplish the required result so I have to manually write a SELECT Statement.
I want to display one single record in my UI. This should be the most recently generated record (which means it has the highest ID Number) associated with a category that we call "ASMS". In other words, look through all the rows that have ASMS#123, find the one that has the highest ID and then return the contents of one column cell.
ASMS: Entries are classified by 11 specific ASMS numbers.
ID: AutoGenerated
PPRECORD: New entries being inserted each day
I hope the image makes more sense.
//RETURN ONLY THE LATEST RECORD
//https://besterdev-api.apps.pcfepg3mi.gm.com/api/v1/pprecords/latest/{asmsnumber}
#RequestMapping("/pprecords/latest/{asmsNumber}")
public List<Optional<PriorityProgressEntity>> getLatestRecord(#PathVariable(value = "asmsNumber") String asmsNumber) {
List<Optional<PriorityProgressEntity>> asms_number = priorityprogressrepo.findFirst1ByAsmsNumber(asmsNumber);
return asms_number;}
The ReactJS FE makes an AXIOS.get and I can retrieve all the records associated with the ASMS, but I do not have the skill to display only JSON object that has the highest ID value. I'm happy to do this in the FE also.
I tried Derived Queries. .findFirst1ByAsmsNumber(asmsNumber) does not consider the highest ID number.
Try this:
SELECT pprecord FROM YourTable WHERE id =
(SELECT MAX(id) FROM YourTable WHERE asms = '188660')
Explanation:
First line select pprecord, second line select the id
I'll improve the answer if any additional question. Upvotes and acceptions are appreciated~
I want to update rows on a table which contains the following colums:
`parameter_name`(PRIMARY KEY),
`option_order`,
`value`.
I have a collection called parameterColletion which contains "parameterNames", "optionOrders" and "values". This collection does not have a fixed value, it can receive the quantity of parameters you want to.
Imagine I have 5 parameters inside my collection (I could have 28, or 10204 too) and I am trying to update the rows of the database using the next query. Example of query:
UPDATE insight_app_parameter_option
SET option_order IN (1,2,3,4,5), value IN ('a','b','c','d','e')
WHERE parameter_name IN ('name1', 'name2', 'name3', 'name4', 'name5')
But this isn't doing the job, instead it gives back an error which says You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN (1,2,3,4,5), value IN ('a','b','c','d','e') WHERE parameter_name IN ('name1'' at line 2
1,2,3,4,5 -> Represent the option orders inside parameterCollection.
'a','b','c','d','e' -> Represent the values inside parameterCollection.
'name1', 'name2', 'name3', 'name4', 'name5' -> Represent the names inside parameterCollection.
I know how to update each parameter by separate but i would like to do it all together. Here are some links I visited where people asked the same question but they used a fixed colletion of objects, not a mutable one.
MySQL - UPDATE multiple rows with different values in one query
Multiple rows update into a single query
SQL - Update multiple records in one query
That's not possible with MySQL. The error you are receiving is a syntax error. You are not able to set multiple values at once. This is the correct syntax to a UPDATE statement: (ref)
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET assignment_list
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
value:
{expr | DEFAULT}
assignment:
col_name = value
assignment_list:
assignment [, assignment] ...
You need to create separate UPDATEs for each row. I suggest executing all in a single transaction, if its the case.
The correct syntax for your example is:
UPDATE insight_app_parameter_option
SET option_order = 1, value = 'a'
WHERE parameter_name = 'name1';
UPDATE insight_app_parameter_option
SET option_order = 2, value = 'b'
WHERE parameter_name = 'name2';
UPDATE insight_app_parameter_option
SET option_order = 3, value = 'c'
WHERE parameter_name = 'name3';
...
There's 2 tables;
OITM that references an Item's information and stock amounts
OINM that references all changes to all Item's stock amounts.
Currently, I've already built a SQL that lets me SELECT new changes to Item stock by joining the tables, but I've run into the issue that sometimes there's duplicate entries, when OINM had two changes to the same Item.
This is the SQL i currently have is as follows:
SELECT T0.\"ItemCode\", T0.\"WhsCode\", T0.\"OnHand\", T0.\"IsCommited\", T0.\"OnOrder\", T1.\"DocDate\", T1.\"DocTime\"
FROM KA_DEV6.OITW T0,KA_DEV6.OINM T1
WHERE T0.\"WhsCode\" = '01' AND T0.\"ItemCode\" = T1.\"ItemCode\"
AND (T1.\"DocDate\" > '2019-10-20' OR (T1.\"DocDate\" = '2019-10-20' AND T1.\"DocTime\" >= '1025'))
This outputs the following result:
|ItemCode:CC01.NB.C.LF.F.LI.V.0813.GRCE|WhsCode:01|OnHand:8.000000|IsCommited:4.000000|OnOrder:0.000000|DocDate:2019-10-22 00:00:00.000000000|DocTime:1024
|ItemCode:JO.C.LF.U.LI.V.0004. 22.NG|WhsCode:01|OnHand:1.000000|IsCommited:0.000000|OnOrder:0.000000|DocDate:2019-10-21 00:00:00.000000000|DocTime:1223
|ItemCode:JO.I.FT.M.AB.C.0106. L.NG|WhsCode:01|OnHand:32.000000|IsCommited:0.000000|OnOrder:0.000000|DocDate:2019-10-21 00:00:00.000000000|DocTime:1401
|ItemCode:JO.I.FT.M.AB.C.0106. L.NG|WhsCode:01|OnHand:38.000000|IsCommited:0.000000|OnOrder:0.000000|DocDate:2019-10-21 00:00:00.000000000|DocTime:1402
The issue is that there are entries that have the same ItemCode, and I only need the most recent change. (Thus, I'd need to filter out the 3rd result, only returning the most recent which is 4th.)
How could I go about this? Because my ordering is by 2 fields (DocDate and DocTime), and then filter out the duplicates.
Ordering is already something i can do and works which is adding
ORDER BY T1.\"DocDate\", T1.\"DocTime\" ASC
But how do i filter out duplicates?
Expected output would be:
|ItemCode:CC01.NB.C.LF.F.LI.V.0813.GRCE|WhsCode:01|OnHand:8.000000|IsCommited:4.000000|OnOrder:0.000000|DocDate:2019-10-22 00:00:00.000000000|DocTime:1024
|ItemCode:JO.C.LF.U.LI.V.0004. 22.NG|WhsCode:01|OnHand:1.000000|IsCommited:0.000000|OnOrder:0.000000|DocDate:2019-10-21 00:00:00.000000000|DocTime:1223
|ItemCode:JO.I.FT.M.AB.C.0106. L.NG|WhsCode:01|OnHand:38.000000|IsCommited:0.000000|OnOrder:0.000000|DocDate:2019-10-21 00:00:00.000000000|DocTime:1402
Regards
EDIT: For anyone reading in the future, and checking out the answer, do note that for my case, the actual ordering of the information didnt matter, since i dont care about it being the newst change, only filtering out duplicates. For the actual most recent table, you need to change the Order By clause from the sub query to ORDER BY T1.\"DocDate\",T1.\"DocTime\" DESC and optionally, at the end of the entire query again to order the results.
You can use the ROW_NUMBER windowing function to this like this:
SELECT *
FROM (
SELECT T0.\"ItemCode\", T0.\"WhsCode\", T0.\"OnHand\", T0.\"IsCommited\", T0.\"OnOrder\", T1.\"DocDate\", T1.\"DocTime\",
ROW_NUMBER() OVER (PARTITION BY T0.\"ItemCode\" ORDER BY T1.\"DocTime\" DESC) AS RN
FROM KA_DEV6.OITW T0
JOIN KA_DEV6.OINM T1 ON T0.\"WhsCode\" = '01' AND T0.\"ItemCode\" = T1.\"ItemCode\"
WHERE T1.\"DocDate\" > '2019-10-20' OR (T1.\"DocDate\" = '2019-10-20' AND T1.\"DocTime\" >= '1025')
) X
WHERE RN = 1
Note -- I also used standard join syntax not the 20+ year old syntax you were using.
Can we change content of Power BI report using Power BI REST API, say in
some report 'Col A' has been used and I want to change it to 'Col
B'. 'Col A' and 'Col B' are in same dataset and same table.
In updatereportcontent API, what can be the possible value of
sourcetypeenum apart from 'ExistingReport'?
https://learn.microsoft.com/en-us/rest/api/power-bi/reports/updatereportcontent#sourcetypeenum
I am using Power BI native application to do this task.
First about question #2 - as you can see in the link you gave, ExistingReport is the only possible value.
About your first question - you can't do this directly using the API. However, you can use a text value parameter (let's name it ColName) to hold the name of the column you want to select. Modify the M query for fetching the data from the database by changing it from:
let
Source = Sql.Database(ServerName, DatabaseName, [Query="select Col1, Col2, ColA from Sales.Orders"])
in
Source
to:
let
Source = Sql.Database(ServerName, DatabaseName, [Query="select Col1, Col2, " & ColName & " as ColA from Sales.Orders"])
in
Source
Then use Update Parameters or Update Parameters In Group API to change the value of ColName parameter (to let's say ColB). If this is imported dataset, you must refresh it using Refresh Dataset or Refresh Dataset In Group after that.
Image 1 is the current data,
Image 2 is the data i need to store into a new table. Thing is i want to combine all the same ITEM_NO and put it as a comma separated value and insert into a new table.
Whilst I don't think storing data like this is a good idea at all (see what others have said in the comments) it is possible by doing:
SELECT REFERENCE_NO,
ITEM_NO,
ROLES = STUFF((SELECT N', ' + ENTITY_ROLE
FROM dbo.MyTable AS p2
WHERE p2.ITEM_NO = p.ITEM_NO
ORDER BY ENTITY_ROLE
FOR XML PATH(N'')), 1, 2, N'')
FROM dbo.MyTable AS p
GROUP BY REFERENCE_NO, ITEM_NO
ORDER BY ITEM_NO;
A demo of this in action: SQL Fiddle