Im using the iff expression in the query. trying to run it but it says this missing a closing parenthesis, bracket. but i checked in the expression. not sure about which one is missing. thanks!
=IIf([Project status]="Project request", "1", IIf([Project status]="Project charter", "2", IIf([Project status]="Started project", "3", IIf([Project status]="Technically closed", "4", IIf([Project status]="Closed", "5", IIf([Project status]="Cancelled", "6", IIf([Project status]="Rejected ", "7","null")))
Try this IIF,
=IIf([Project status] = "Project request", "1", IIf([Project status] = "Project charter", "2", IIf([Project status] = "Started project", "3", IIf([Project status] = "Technically closed", "4", IIf([Project status]="Closed", "5", IIf([Project status] = "Cancelled", "6", IIf([Project status]= "Rejected ", "7", "null")))))))
You could solve your problem much simply by creating a new table.
tbl_projStatus
==============
projStatus | projectCode
--------------------+---------------
Project request | 1
Project charter | 2
Started project | 3
Technically closed | 4
Closed | 5
Cancelled | 6
Rejected | 7
Then you could use a DLookup, like
= DLookup("projectCode", "tbl_projStatus", "projStatus = " & [Project status])
Related
I have CLOB field with JSON data :
[
{
"name": "Rahul",
"LName": "Sharma",
"salary": "20000",
"Age": "35"
},
{
"name": "Kunal",
"LName": "Vohra",
"salary": "10000",
"Age": "25"
}
]
and I need update value in only one element of that array, for example in record with name: Kunal I need change salary.
I try json_transform() but with this I transform every field salary to new value.
json_transform(json_field_in_table, SET '$.salary' = 15000)
You may use filter expression in JSON path of json_transform function to update specific objects:
with a(col) as (
select q'$[
{
"name": "Rahul",
"LName": "Sharma",
"salary": "20000",
"Age": "35"
},
{
"name": "Kunal",
"LName": "Vohra",
"salary": "10000",
"Age": "25"
}
]$' from dual
)
select
json_transform(
col,
set '$[*]?(#.name == "Kunal").salary' = '100'
) as res
from a
RES
[{"name":"Rahul","LName":"Sharma","salary":"20000","Age":"35"},{"name":"Kunal","LName":"Vohra","salary":"100","Age":"25"}]
fiddle
Note that "10000" is a string in JSON, numbers should be used without quotes: {"salary: 10000}
You can't use json_transform because json_transform, json_exists... evaluate on the whole JSON document not on pieces of it,
even a json_exists with "'$?(#.name == "Kunal")'" will consider that the whole document matches and then update all "salary" fields.
(https://docs.oracle.com/en/database/oracle/oracle-database/12.2/adjsn/condition-JSON_EXISTS.html#GUID-8A0043D5-95F8-4918-9126-F86FB0E203F0)
but you can:
select json_arrayagg(json_object (
'name' value name,
'LName' value lname,
'salary' value case when name = 'Kunal' then 15000 else salary end,
'Age' value age)) as js
from
json_table(q'~[
{
"name": "Rahul",
"LName": "Sharma",
"salary": "20000",
"Age": "35"
},
{
"name": "Kunal",
"LName": "Vohra",
"salary": "10000",
"Age": "25"
}
]~','$[*]'
columns (
name VARCHAR2(64) path '$.name',
LName VARCHAR2(64) path '$.LName',
salary NUMBER path '$.salary',
age NUMBER path '$.Age'
));
I have two tables as follows
user table
user_id
name
1
zia
2
john
3
raza
subject table
data_id
user_id
subject
1
1
Math
2
1
Chem
3
1
Bio
4
2
Math
5
2
Phy
when I am querying data i am getting results like this:
[
{
"user_id": "1",
"name": "zia",
"subject": [
"Math",
"Chem",
"Bio"
]
},
{
"user_id": "2",
"name": "john",
"subject": [
"Math",
"Phy"
]
},
]
My query is as follows
SELECT
users.user_id,
users.name,
GROUP_CONCAT(subjects.subject) sub
FROM
`users`
INNER JOIN subjects ON users.user_id = subjects.user_id
GROUP BY
subjects.user_id;
but actually I want to get data in following way:
the resuluts shown above are in such a way that if an entry from user table does not have coresponding enteries in subject table even then we must have user name and user id in our rsults as follows
[
{
"user_id": "1",
"name": "zia",
"subject": [
"Math",
"Chem",
"Bio"
]
},
{
"user_id": "2",
"name": "john",
"subject": [
"Math",
"Phy"
]
},
{
"user_id": "3",
"name": "Raza",
}
]
Here as you see that we have data in such a way that all the enteries from user table are shown alog with subject enteries from subject table if they match otherwise every user table entery is showing up with no affect.
*PLease help me in solving this issue **
You probably need to use LEFT JOIN instead of INNER JOIN, because you want to retrieve user without subject too
I am trying to ingest JSON array data (specifically the 'Objects' array) into Azure data explorer, as per this Microsoft article. (Only the JSON Array section)
https://learn.microsoft.com/en-us/azure/data-explorer/ingest-json-formats?tabs=kusto-query-language&source=docs#ingest-json-records-containing-arrays
My JSON data is different to the example, as it has an additional layer in the JSON, when expanding the raw event row to the second table, the row entered is blank. I assume the function can't find 'Objects' using the kusto function?
.create function EventRecordsExpand() {
rawhsievents
| mv-expand Objects = Event
| project
AlarmState = tostring(Objects["AlarmState"]),
AreaOfInterest = tostring(Objects["AreaOfInterest"]),
Category = tostring(Objects["Category"]),
EncodedMessage = tostring(Objects["EncodedMessage"]),
Fullname = tostring(Objects["Fullname"]),
Id = tolong(Objects["Id"]),
Message = tostring(Objects["Message"]),
ReceiptTime = todatetime(Objects["ReceiptTime"]),
RecordTime = todatetime(Objects["RecordTime"]),
Severity = tostring(Objects["Severity"]),
User = tostring(Objects["User"])
}
An example of my JSON data is below:
{
"ExportedEvents": {
"Header": {
"SystemName": "Mids",
"StartDate": "2020-11-03T12:28:00.55Z",
"EndDate": "2020-11-03T12:28:11.521Z"
},
"Objects": [{
"AlarmState": "",
"AreaOfInterest": "",
"Category": "Action",
"EncodedMessage": "Kernel,469,M(Lib,101,S\"RequestExportXML\")",
"Fullname": "System Resources.XML Interface.Support Processes.Batch Scheduler.Batch Schedule Scanner",
"Id": 456020,
"Message": "RequestExportXML request rejected - Invalid configuration",
"ReceiptTime": "2020-11-03T12:28:00.55Z",
"RecordTime": "2020-11-03T12:28:00.55Z",
"Severity": "Low",
"User": "Schedule"
},
{
"AlarmState": "",
"AreaOfInterest": "",
"Category": "Action",
"EncodedMessage": "Kernel,469,M(Lib,101,S\"RequestExportXML\")",
"Fullname": "System Resources.XML Interface.Support Processes.Batch Scheduler.Batch Schedule Scanner",
"Id": 456020,
"Message": "RequestExportXML request rejected - Invalid configuration",
"ReceiptTime": "2020-11-03T12:28:00.551Z",
"RecordTime": "2020-11-03T12:28:00.551Z",
"Severity": "Low",
"User": "Schedule"
}
]
}
}
Do i need a second mv-expand to expand the data twice?
it seems like you're mv-expanding the wrong dynamic object, and you need to access ExportedEvents.Objects first.
for example:
datatable(Event:dynamic)
[
dynamic({
"ExportedEvents": {
"Header": {
"SystemName": "Mids",
"StartDate": "2020-11-03T12:28:00.55Z",
"EndDate": "2020-11-03T12:28:11.521Z"
},
"Objects": [{
"AlarmState": "",
"AreaOfInterest": "",
"Category": "Action",
"EncodedMessage": "Kernel,469,M(Lib,101,S\"RequestExportXML\")",
"Fullname": "System Resources.XML Interface.Support Processes.Batch Scheduler.Batch Schedule Scanner",
"Id": 456020,
"Message": "RequestExportXML request rejected - Invalid configuration",
"ReceiptTime": "2020-11-03T12:28:00.55Z",
"RecordTime": "2020-11-03T12:28:00.55Z",
"Severity": "Low",
"User": "Schedule"
},
{
"AlarmState": "",
"AreaOfInterest": "",
"Category": "Action",
"EncodedMessage": "Kernel,469,M(Lib,101,S\"RequestExportXML\")",
"Fullname": "System Resources.XML Interface.Support Processes.Batch Scheduler.Batch Schedule Scanner",
"Id": 456020,
"Message": "RequestExportXML request rejected - Invalid configuration",
"ReceiptTime": "2020-11-03T12:28:00.551Z",
"RecordTime": "2020-11-03T12:28:00.551Z",
"Severity": "Low",
"User": "Schedule"
}
]
}
})
]
| mv-expand Objects = Event.ExportedEvents.Objects
| project
AlarmState = tostring(Objects["AlarmState"]),
AreaOfInterest = tostring(Objects["AreaOfInterest"]),
Category = tostring(Objects["Category"]),
EncodedMessage = tostring(Objects["EncodedMessage"]),
Fullname = tostring(Objects["Fullname"]),
Id = tolong(Objects["Id"]),
Message = tostring(Objects["Message"]),
ReceiptTime = todatetime(Objects["ReceiptTime"]),
RecordTime = todatetime(Objects["RecordTime"]),
Severity = tostring(Objects["Severity"]),
User = tostring(Objects["User"])
returns:
| AlarmState | AreaOfInterest | Category | EncodedMessage | Fullname | Id | Message | ReceiptTime | RecordTime | Severity | User |
|------------|----------------|----------|-------------------------------------------|-----------------------------------------------------------------------------------------|--------|-----------------------------------------------------------|-----------------------------|-----------------------------|----------|----------|
| | | Action | Kernel,469,M(Lib,101,S"RequestExportXML") | System Resources.XML Interface.Support Processes.Batch Scheduler.Batch Schedule Scanner | 456020 | RequestExportXML request rejected - Invalid configuration | 2020-11-03 12:28:00.5500000 | 2020-11-03 12:28:00.5500000 | Low | Schedule |
| | | Action | Kernel,469,M(Lib,101,S"RequestExportXML") | System Resources.XML Interface.Support Processes.Batch Scheduler.Batch Schedule Scanner | 456020 | RequestExportXML request rejected - Invalid configuration | 2020-11-03 12:28:00.5510000 | 2020-11-03 12:28:00.5510000 | Low | Schedule |
{
"people": {
"Man": {
"Employee": "50",
"Student": "91",
"Artist": "80",
"Clark": "50"
},
"Woman": {
"Employee": "21",
"Student": "01",
"Artist": "00",
"k3": "30",
"Clark": "68"
}
}
}
How can I Update Employee Value From Man Object. I want something similar to below mysql query.
UPDATE TABLE
SET Column = JSON_SET(Column, '$.people.Man.Employee', '51')
WHERE Id=1234567890;
MariaDB [**********]> SELECT VERSION();
+--------------------------------------------+
| VERSION() |
+--------------------------------------------+
| 10.3.17-MariaDB-1:10.3.17+maria~bionic-log |
+--------------------------------------------+
Firstly, fix the keys within the JSON column by adding quotes for each, and values by adding quotes for some which starts with zeroes and go on with other digits.
Then apply :
UPDATE tab
SET Col = JSON_SET(
Col,
"$.people.Man.Employee", "50",
"$.people.Man.Employee", "51"
)
WHERE ID = 1234567890;
Demo
Even, I don't see any problem with the following
UPDATE tab
SET
Col = JSON_SET(Col, '$.people.Man.Employee', '51')
WHERE
Id = 1234567890;
Demo
I have a table that I defined one column to receive zero 0 as value. I did this because zero 0 represents all values. The table's name is agendas and the column it's turmas_id, this column has relationship with table turmas but turmas_id in agendas it's not a foreignkey because I can add 0 as saied before.
The problem is when I make a JOIN using these tables because I need return all attributes with zero value and valid keys added in table turmas.
I tried use LEFT JOIN and INNER JOIN but the result it's not what I wait. I can use JOIN if id exists in table turmas and table agendas because it's a valid foreign key but I can't return other values with 0 in agendas attribute turmas_id and this is exactly what I need.
How could I do this ?
I need display this result
//table agendas
-----------------------------------------
turmas_id | descricao
-----------------------------------------
0 | this attribute contain zero and it's not exists in table turmas
16 | table turmas contain id 16 it is a foreign key
0 | this attribute contain zero and it's not exists in table turmas
23 | table turmas contain id 23 it is a foreign key
SQL
$agendamentos = $this->Agenda->query("SELECT * FROM responsavel_alunos RespAlunos "
. "INNER JOIN pessoas Responsavel ON (Responsavel.id = RespAlunos.pessoas_id) "
. "INNER JOIN pessoas Aluno ON (Aluno.id = RespAlunos.pessoas_id1) "
. "INNER JOIN matriculas Matricula ON (Matricula.pessoas_id = Aluno.id) "
. "RIGHT JOIN turmas Turma ON (Turma.id = Matricula.turmas_id OR Turma.id = 0) "
. "INNER JOIN escolas Escola ON (Escola.id = Matricula.escolas_id) "
. "INNER JOIN agendas Agenda ON (Agenda.turmas_id = Turma.id) "
. "WHERE Responsavel.id = ? ORDER BY Agenda.created DESC "
, array($id)); //id do responsavel
Model
JSON result
{
"status": "1",
"result": [
{
"RespAlunos": {
"id": "5",
"pessoas_id": "8",
"pessoas_id1": "9",
"created": "2015-09-21 10:25:46",
"modified": "2015-09-21 10:25:46"
},
"Responsavel": {
"id": "8",
"nome": "responsavel ",
"email": "responsavel #hotmail.com",
"tipopessoas_id": "3",
"status": "1",
"created": "2015-09-21 10:17:17",
"modified": "2015-09-21 10:17:17"
},
"Aluno": {
"id": "9",
"nome": "aluno",
"email": "aluno#gmail.com",
"tipopessoas_id": "1",
"status": "1",
"created": "2015-09-21 10:18:41",
"modified": "2015-09-21 10:18:41"
},
"Matricula": {
"id": "6",
"referencia": "238",
"pessoas_id": "9",
"turmas_id": "4",
"escolas_id": "2",
"status": "1",
"created": "2015-09-21 10:35:08",
"modified": "2016-02-18 10:51:20"
},
"Turma": {
"id": "4",
"descricao": "4º ano",
"created": "2015-09-21 10:31:32",
"modified": "2015-09-21 10:31:32"
},
"Escola": {
"id": "2",
"descricao": "Santa Luz Unidade 2",
"created": "2015-09-17 23:09:38",
"modified": "2015-09-17 23:09:38"
},
"Agenda": {
"id": "34",
"data": "2016-02-29 14:40:00",
"descricao": "<p>teste 1</p>\r\n",
"escolas_id": "2",
"turmas_id": "4",
"created": "2016-02-29 14:40:21",
"modified": "2016-02-29 14:40:21"
}
},
{
"RespAlunos": {
"id": "5",
"pessoas_id": "8",
"pessoas_id1": "9",
"created": "2015-09-21 10:25:46",
"modified": "2015-09-21 10:25:46"
},
"Responsavel": {
"id": "8",
"nome": "responsavel ",
"email": "responsavel #hotmail.com",
"tipopessoas_id": "3",
"status": "1",
"created": "2015-09-21 10:17:17",
"modified": "2015-09-21 10:17:17"
},
"Aluno": {
"id": "9",
"nome": "aluno",
"email": "aluno#gmail.com",
"tipopessoas_id": "1",
"status": "1",
"created": "2015-09-21 10:18:41",
"modified": "2015-09-21 10:18:41"
},
"Matricula": {
"id": "6",
"referencia": "238",
"pessoas_id": "9",
"turmas_id": "4",
"escolas_id": "2",
"status": "1",
"created": "2015-09-21 10:35:08",
"modified": "2016-02-18 10:51:20"
},
"Turma": {
"id": "4",
"descricao": "4º ano",
"created": "2015-09-21 10:31:32",
"modified": "2015-09-21 10:31:32"
},
"Escola": {
"id": "2",
"descricao": "Santa Luz Unidade 2",
"created": "2015-09-17 23:09:38",
"modified": "2015-09-17 23:09:38"
},
"Agenda": {
"id": "27",
"data": "2016-02-29 08:24:00",
"descricao": "descricao",
"escolas_id": "2",
"turmas_id": "4",
"created": "2016-02-29 08:25:20",
"modified": "2016-02-29 08:25:20"
}
}
]
}
try to use IN ? instead of using = ? in your WHERE clause since your using an array variable
Can you try RIGHT JOIN instead?
"RIGHT JOIN turmas Turma ON (Turma.id = Matricula.turmas_id OR Turma.id = 0)"
because TABLE1 LEFT JOIN TABLE2 means all rows from TABLE1 will be selected, even if there are no matching rows in TABLE2.
RIGHT JOIN is the opposite of it. So use RIGHT JOIN so that you can return your TURMA records based from the ON condition, even if there are no matching records from the preceding table.
Try this one.
$agendamentos = $this->Agenda->query("SELECT * FROM responsavel_alunos RespAlunos "
. "INNER JOIN pessoas Responsavel ON (Responsavel.id = RespAlunos.pessoas_id) "
. "INNER JOIN pessoas Aluno ON (Aluno.id = RespAlunos.pessoas_id1) "
. "INNER JOIN matriculas Matricula ON (Matricula.pessoas_id = Aluno.id) "
. "(SELECT turmas as turma WHERE (turma.id = Matricula.turmas_id OR turma.id = 0)) AS TURMA"
. "INNER JOIN escolas Escola ON (Escola.id = Matricula.escolas_id) "
. "INNER JOIN agendas Agenda ON (Agenda.turmas_id = Turma.id) "
. "WHERE Responsavel.id IN ? ORDER BY Agenda.created DESC "
, array($id)); //id do responsavel