I'm attempting to do an inner join on CardID, which is present in 2 tables:
PCARDS_ILL_DBO_CARD and tExceptionsAll2.
In PCARDS_ILL_DBO_CARD it is a 'Number' and in tExceptionsAll2 it is 'Short Text.'
I've looked at answers to similar questions posted on Stackoverflow and implemented them, but I'm still getting an error.
I am unable to change any formatting in PCARDS_ILL_DBO_CARD; several other queries in different databases rely on tExceptionsAll2 having the current formatting and data types it has.
Here's what I have:
SELECT tExceptionsAll2.ID
, tExceptionsAll2.CardholderName
, PCARDS_ILL_DBO_CARD.PERSON_ID
, tExceptionsAll2.CardType
, tExceptionsAll2.Duration
, tExceptionsAll2.ExceptionType
, tExceptionsAll2.STL AS [Exp STL]
, tExceptionsAll2.CL AS [Exp CL]
, PCARDS_ILL_DBO_CARD.TRANS_LIMIT_AMT AS [Card STL]
, PCARDS_ILL_DBO_CARD.MONTH_LIMIT_AMT AS [Card CL]
, tExceptionsAll2.TerminationDate
FROM PCARDS_ILL_DBO_CARD INNER JOIN tExceptionsAll2 ON (PCARDS_ILL_DBO_CARD.CARD_ID = CAST (tExceptionsAll2.CardID AS INT)) AND
(PCARDS_ILL_DBO_CARD.PERSON_ID = tExceptionsAll2.CardholderUIN)
WHERE (((tExceptionsAll2.STL)>0) AND
((tExceptionsAll2.CL)>0) AND
((PCARDS_ILL_DBO_CARD.TRANS_LIMIT_AMT)<>[tExceptionsAll2].[STL]) AND
((PCARDS_ILL_DBO_CARD.MONTH_LIMIT_AMT)<>[tExceptionsAll2].[CL]) AND
((tExceptionsAll2.TerminationDate) Is Null));
Here's the error:
Related
I have multiple models in Sparx Enterprise Architect in file-based, i.e. using MS access.
I'm using a custom template to populate a table with data from object's properties, including some with <memo> fields.
This is the query i'm using in the template fragment:
SELECT obj.object_id,
obj.Stereotype,
objp.Property as Prop,
switch(objp.Value = '<memo>', objp.Notes, objp.Value LIKE '{*}',
NULL, 1=1, objp.Value) AS Val,
(SELECT tobj2.ea_guid & tobj2.Name FROM t_object tobj2 WHERE
tobj2.ea_guid = objp.Value) AS [Obj-Hyperlink]
FROM t_object obj
INNER JOIN t_objectproperties objp
ON (obj.object_id = objp.object_id)
WHERE obj.object_id = #OBJECTID# AND obj.Stereotype='Data-
Stream' AND objp.Property NOT IN ('isEncapsulated')
ORDER BY objp.Property ASC;
I found that the when these fields are longer than 249 chars I get an error message when generating the reports and the cell in the generated table is simply empty. This is also noticeable with a query:
The error I'm getting states:
"Error Processing xml document: an invalid character was found in text context"
Is there any workarround to enable including the <memo> fields' data with more than 249 chars in the reports?
Any help is much appreciated.
I've found a workaround for this by joining two queries with a "Union all". The first query will handle the non-memo fields with the switch function and the second one the memo fields without the switch function.
select
obj.object_id,
obj.Stereotype,
objp.Property as Prop,
objp.Notes AS Val,
(
SELECT
tobj2.ea_guid & tobj2.Name
FROM
t_object tobj2
WHERE
tobj2.ea_guid = objp.Value
) AS [Obj-Hyperlink]
from
t_objectproperties objp
left join t_object obj on (obj.object_id = objp.object_ID)
where
obj.object_id = #OBJECTID#
AND obj.Stereotype = 'Data-Stream'
AND objp.Property NOT IN ('isEncapsulated')
AND objp.Value = "<memo>"
UNION ALL
SELECT
obj2.object_id,
obj2.Stereotype,
objp2.Property as Prop,
switch(
objp2.Value LIKE '{*}', NULL, 1 = 1, objp2.Value
) AS Val,
(
SELECT
tobj2.ea_guid & tobj2.Name
FROM
t_object tobj2
WHERE
tobj2.ea_guid = objp2.Value
) AS [Obj-Hyperlink]
FROM
t_object obj2
INNER JOIN t_objectproperties objp2 ON (obj2.object_id = objp2.object_id)
WHERE
obj2.object_id = #OBJECTID#
AND obj2.Stereotype = 'Data-Stream'
AND objp2.Property NOT IN ('isEncapsulated')
and objp2.Value <> "<memo>"
order by
3 asc;
Thanks a lot #geertbellekens for your comment which was crucial to find this solution.
The aim is to join the same table and retreive two different columns using where clause
SELECT a.analyst_assigned
, count(a.case_id) AS Pending
, count(b.case_id) AS Completed
, sum(b.total_errors) AS Errors
FROM cases_main as a
WHERE a.team_qc1_qa2 = "qa"
and a.q_status in ("Not Started","Under Review","Follow-up")
and a.p_date_worked between #03/08/2021# and #03/14/2021#
INNER JOIN cases_main as b
ON a.analyst_assigned = b.analyst_assigned
WHERE b.team_qc1_qa2 = "qa"
and b.q_status in ("Completed: No Error","Completed: Feedback")
and b.p_date_worked between #03/08/2021# and #03/14/2021#
GROUP
BY b.analyst_assigned;
Try this simpler approach:
SELECT a.analyst_assigned
, abs(sum(q_status Like "Completed*")) AS Pending
, abs(sum(q_status Not Like "Completed*")) AS Completed
, sum(b.total_errors) AS Errors
FROM cases_main as a
WHERE a.team_qc1_qa2 = "qa"
and a.p_date_worked between #03/08/2021# and #03/14/2021#
GROUP BY a.analyst_assigned
I have a problem, I have a varchar field that contains m values separated by commas:
garage 1,2
garage 1,3,5
I have the following query
select
json_object(
'data',
json_objectagg(
r.slug,
json_object(
'nome',r.name,
'localizacao',
json_object(
'endereco' , r.address,
'bairro' , r.neighborhood,
'cidade' , r.city,
'estado' , r.state,
'latitude' , r.lat,
'longitude' , r.lng
),
'tipo' , r.type,
'incorporadora' , d.name,
'dormitorios', json_object('legenda', r.rooms, 'quantidade', json_array(r.rooms_quantity)),
'garagem', json_object('legenda', r.garage, 'quantidade', json_array(r.garage_quantity)),
'metragem', json_object('legenda', r.footage, 'minimo', r.min_footage, 'maximo', r.max_footage),
'preco', json_object('minimo', IFNULL(r.min_value, 0), 'maximo' , IFNULL(r.max_value, 0)),
'capa' , ri.filename_default
)
)
) as jsonExport
from realties r
inner join developers d on r.developer_id = d.developer_id
inner join realties_images ri on r.realty_id = ri.realty_id and ri.type_image = 'cover'
where r.active = 'yes' and d.active = 'yes' and ri.active = 'yes';
But when returning json_array with integers it does not match quotes.
being this ["2,Studio"] ["1,2,3"]
but I needed it to be an array because that other code will fetch the information and I needed it
["2","Studio"] ["1","2","3"]
I already tried array_objectagg and everything is something, can anyone help me?
The best solution would be to normalize the database and avoid storing multiple values in one field.
Another solution would be to retrieve the resultset and use some kind of server scripting, process it and then convert it to JSON.
You could write your own MySQL functions to explode comma separated values, e.g like this. However, my advise would be to stick with #1. It will save you time in a long term.
I have two tables that i am working with. The first table is called temp6 with columns labeled as bsite, bsector, msite, msector, esite, esector, bpn, epn. The second table is called homdatapairs with columns labeled as fromcell, fromsector, tocell, tosector, hocount, percentage.
The goal is to produce a table that consists of bsite, bsector, msite, msector, hocount and percentage. The problem im running into is that the pairing of bsite, bsector, msite, msector does not exist in the homdatapairs table. So logically it should return the bsite, bsector, msite, msector, hocount and percentage leaving NULL values in hocount and percentage but it is not returning anything at all (no errors are occuring either).
Here is my query:
SELECT t6.bsite
, t6.bsector
, t6.msite
, t6.msector
, IFNULL(p.hocount, 0)
, IFNULL(p.percentage, 0)
FROM homdatapairs p
, temp6 t6
WHERE t6.bsite = p.fromcell
AND t6.bsector = p.fromsector
AND t6.msite = p.tocell
AND t6.msector = p.tosector;
I was able to figure it out. Here is the query that works.
SELECT DISTINCT t6.bsite, t6.bsector, t6.msite, t6.msector, IF(t6.msite = p.tocell AND t6.msector = p.tosector, IFNULL(p.hocount,0), 0), IF(t6.msite = p.tocell AND t6.msector = p.tosector, IFNULL(p.percentage, 0), 0)
FROM homdatapairs p, temp6 t6
WHERE t6.bsite = p.fromcell AND t6.bsector = p.fromsector;
I have a contact table I wish to query when a certain condition exists. I tried the query below but am getting a syntax error.
SELECT *
FROM contact_details
WHERE contactDeleted` =0
AND IF ( contactVisibility = "private"
, SELECT * FROM contact_details
WHERE contactUserId = 1
, IF( contactVisibility = "group"
, SELECT * FROM contact_details
WHERE contactGroup = 3
)
)
If I'm understanding your question correctly (which is difficult with the lack of info you've provided. Sample datasets and expected outcomes are typically helpful), then I don't believe you need IFs at all for what you want. The following will return contacts that are not deleted and who either have (visibility = "private" and userId = 1) OR (visibility = "group" and group = 3)
SELECT *
FROM contact_details
WHERE contactDeleted = 0
AND (
(contactVisibility = "public")
OR
(contactVisibility = "private" AND contactUserId = 1)
OR
(contactVisibility = "group" AND contactGroup = 3)
)
I am assuming you want to use the IF() function and not the statement which is for stored functions..
Refer to this link for more information on that.
Notice that you have put 2 select statements in there, where the custom return values are supposed to be. So you are returning a SELECT *... now notice that in your upper level sql statement you have an AND.. so you basically writing AND SELECT *.. which will give you the syntax error.
Try using .. AND x IN (SELECT *) .. to find if x is in the returned values.
Let me also list this link to make use of an existing and well written answer which may also applicable to your question.