Is it better that I just use the where for update query with conditions or there is a better way to do?
Below is a sample of my SQL query which I wanted to update if the Order_ID = 10 plus payment_check is N or response_msg is null, kindly correct me if my query is wrong.
UPDATE dbo.sample1
SET Payment_Generated = 'Y',
Transaction_ID = '123',
Response_Msg = 'ok',
Response_Code = '1',
Created_on = '2020-05-29T11:29:30'
WHERE Order_ID = '10' and Payment_Check = 'N' or Response_Code IS NULL
Expected Result if the payment_check is N or response_code is null
Payment_Generated = 'Y',
Transaction_ID = '123',
Response_Msg = 'ok',
Response_Code = '1',
Created_on = '2020-05-29T11:29:30'
Order_ID = '10'
Payment_Check = 'N'
Related
Hi there I'm using MaxDB and trying to update a table and I get the error Missing keyword:WITH. Code: -5015.
Here is my SQL:
UPDATE agm
SET agm_confirm_stat = 'C',
agm_confirm_usr = 'MEDICWARE',
agm_confirm_obs = 'Wellon: Confirmado',
agm_obs = NVL(agm_obs, '') || '\/\/Wellon: Confirmar',
agm_confirm_dthr = TIMESTAMP
WHERE (agm_pac = '319900')
AND (
agm_obs NOT LIKE '%Wellon: Confirmar%'
OR agm_obs IS NULL
)
AND (agm_str_cod = 'FBC')
AND (agm_hini = '2022-12-07 08:00:00')
AND (agm_confirm_stat != 'C')
AND (agm_stat = 'A')
The below query returns value such as - 'GA','CA','AL'
Query#1
(SELECT Upper(hzg.geography_name)
FROM hz_geographies HZG,
hz_geography_identifiers HZGI,
hz_geography_identifiers HZGI1
WHERE hzg.country_code = 'US'
AND hzg.geography_use = 'MASTER_REF'
AND hzg.geography_type = 'STATE'
AND hzg.geography_element1 = 'United States'
AND hzgi.geography_id = hzg.geography_id
AND hzgi.identifier_subtype = 'STANDARD_NAME'
AND hzgi.identifier_type = 'NAME'
AND hzgi.language_code = 'US'
AND hzgi.geography_use = 'MASTER_REF'
AND hzgi.geography_type = 'STATE'
AND hzgi.primary_flag = 'N'
AND hzgi1.geography_id = hzgi.geography_id
AND hzgi1.identifier_subtype = 'GEO_CODE'
AND hzgi1.identifier_type = 'CODE'
AND hzgi1.language_code = 'US'
AND hzgi1.geography_use = 'MASTER_REF'
AND hzgi1.geography_type = 'STATE'
AND hzgi1.primary_flag = 'N'
AND Substr(hzgi1.identifier_value, 1,
Instr(hzgi1.identifier_value, '-')
- 1) =
pdcc.context_value1)
I want to use the above query in another query such that -
query #2
(SELECT DISTINCT Decode(dir_information_char3, 'Y', 'Yes',
'N', 'No',
'')
FROM pay_dir_card_components_f PDCCF3,
pay_dir_comp_details_f PDCDF3
WHERE PDCCF3.dir_card_id = PDCF.dir_card_id
and pdcc.context_value1 = PDCCF3.context_value1
AND PDCCF3.dir_card_comp_id = PDCDF3.dir_card_comp_id
AND PDCDF3.dir_information_category =
'HRX_US_WTH_STATE_GA')
HRX_US_WTH_STATE_GA Should change according to query #1.
i.e. if the query 1 returns 'CA' then query #2 should come like -
(SELECT DISTINCT Decode(dir_information_char3, 'Y', 'Yes',
'N', 'No',
'')
FROM pay_dir_card_components_f PDCCF3,
pay_dir_comp_details_f PDCDF3
WHERE PDCCF3.dir_card_id = PDCF.dir_card_id
and pdcc.context_value1 = PDCCF3.context_value1
AND PDCCF3.dir_card_comp_id = PDCDF3.dir_card_comp_id
AND PDCDF3.dir_information_category =
'HRX_US_WTH_STATE_CA')
how can we do that
Just a simple subquery should do the trick no?
SELECT DISTINCT Decode(dir_information_char3, 'Y', 'Yes',
'N', 'No',
'')
FROM pay_dir_card_components_f PDCCF3,
pay_dir_comp_details_f PDCDF3
WHERE PDCCF3.dir_card_id = PDCF.dir_card_id
and pdcc.context_value1 = PDCCF3.context_value1
AND PDCCF3.dir_card_comp_id = PDCDF3.dir_card_comp_id
AND PDCDF3.dir_information_category =
(SELECT 'HRX_US_WTH_STATE_'||Upper(hzg.geography_name)
FROM hz_geographies HZG,
hz_geography_identifiers HZGI,
hz_geography_identifiers HZGI1
WHERE hzg.country_code = 'US'
AND hzg.geography_use = 'MASTER_REF'
AND hzg.geography_type = 'STATE'
AND hzg.geography_element1 = 'United States'
AND hzgi.geography_id = hzg.geography_id
AND hzgi.identifier_subtype = 'STANDARD_NAME'
AND hzgi.identifier_type = 'NAME'
AND hzgi.language_code = 'US'
AND hzgi.geography_use = 'MASTER_REF'
AND hzgi.geography_type = 'STATE'
AND hzgi.primary_flag = 'N'
AND hzgi1.geography_id = hzgi.geography_id
AND hzgi1.identifier_subtype = 'GEO_CODE'
AND hzgi1.identifier_type = 'CODE'
AND hzgi1.language_code = 'US'
AND hzgi1.geography_use = 'MASTER_REF'
AND hzgi1.geography_type = 'STATE'
AND hzgi1.primary_flag = 'N'
AND Substr(hzgi1.identifier_value, 1,
Instr(hzgi1.identifier_value, '-')
- 1) =
pdcc.context_value1)
I get this error when trying to run this sql scrip, I've searched alot for converting clob to varchar2 but useless
ORA-00932: inconsistent datatypes: expected - got CLOB
SELECT XMLELEMENT("ejada:PrivilegeResourcesList",XMLATTRIBUTES(NOENTITYESCAPING GET_MCR_PARAMETER('xmlns:core') AS "xmlns:core", GET_MCR_PARAMETER('xmlns:ejada') AS "xmlns:ejada"),
XMLAGG(XMLELEMENT("ejada:PrivilegeResourcesInfo",XMLELEMENT("ejada:PrivilegeRec",
XMLELEMENT("ejada:FuncId","F_CODE"),
XMLELEMENT("ejada:SCId","PS_CHANNEL_ID"),
XMLELEMENT("ejada:SrcResourcesList","SRCLIST"),
XMLELEMENT("ejada:TargResourcesList","TRGLIST"),
XMLELEMENT("ejada:Status","PS_STATUS")
)))) .GETCLOBVAL()
INTO P_PRIVILEGE_RESOURCES_LIST
from (
SELECT distinct
F_CODE, PS_CHANNEL_ID,
(
SELECT XMLAGG(XMLELEMENT ("core:ResourceInfo",XMLELEMENT ("core:ResourceId",
DECODE(PR_RESOURCE_TYPE_ID,
'1', XMLELEMENT("core:AcctId",XMLELEMENT("core:AcctId","PR_RESOURCE_VALUE")),
'2', XMLELEMENT("core:BillId",XMLELEMENT("core:BillNum","PR_RESOURCE_VALUE")),
'3', XMLELEMENT("core:BenId",XMLELEMENT("core:BenCode","PR_RESOURCE_VALUE"))
))
,XMLELEMENT("core:ResourceType","PRT_RESOUCE_TYPE_NAME_E")
)).GETCLOBVAL() FROM(SELECT PR_RESOURCE_TYPE_ID, PR_RESOURCE_VALUE, PRT_RESOUCE_TYPE_NAME_E FROM PERMISSION_RESOURCES, PERM_RESOURCE_TYPES WHERE PR_PERMISSION_ID = P.PS_PERMISSION_ID AND PR_USAGE_TYPE = 'S' AND PR_RESOURCE_TYPE_ID = PRT_RESOURCE_TYPE_ID)
) SRCLIST,
(
SELECT XMLAGG(XMLELEMENT ("core:ResourceInfo",XMLELEMENT ("core:ResourceId",
DECODE(PR_RESOURCE_TYPE_ID,
'1', XMLELEMENT("core:AcctId",XMLELEMENT("core:AcctId","PR_RESOURCE_VALUE")),
'2', XMLELEMENT("core:BillId",XMLELEMENT("core:BillNum","PR_RESOURCE_VALUE")),
'3', XMLELEMENT("core:BenId",XMLELEMENT("core:BenCode","PR_RESOURCE_VALUE"))
))
,XMLELEMENT("core:ResourceType","PRT_RESOUCE_TYPE_NAME_E")
)).GETCLOBVAL() FROM(SELECT PR_RESOURCE_TYPE_ID, PR_RESOURCE_VALUE, PRT_RESOUCE_TYPE_NAME_E FROM PERMISSION_RESOURCES, PERM_RESOURCE_TYPES WHERE PR_PERMISSION_ID = P.PS_PERMISSION_ID AND PR_USAGE_TYPE = 'D' AND PR_RESOURCE_TYPE_ID = PRT_RESOURCE_TYPE_ID)
) TRGLIST,
PS_STATUS
FROM FUNCTIONS F , SERVICES S , PERMISSIONS P
WHERE PS_STATUS = 'A'
--AND PS_COMP_TYPE_ID = v_component_type
-- AND Ps_COMPONENT_ID = v_component_id
AND PS_ROLE_ID = P_ROLE_ID
AND PS_ROLE_ID IN (SELECT R_ROLE_ID
FROM ROLES
WHERE R_ROLE_ID=P_ROLE_ID AND
R_COMP_TYPE_ID = 'ORGZ' AND
R_COMPONENT_ID= P_ORG_ID)
AND PS_FUNCTION_ID = F_code
AND F_SERVICE_ID = S_SERVICE_ID
-- AND PS_PERMISSION_ID = PR_PERMISSION_ID
ORDER BY F_CODE
) ;
I'm working on a query that analyzes two records and checks whether one record matches the second record. If record 1 column matches record 2 column then there's no error. If record 1 column does not match record 2 column then there's an error. I want to be able to count the errors per YPID. For the life of me... I can't figure it out. Help!
Here's my query:
select r1.ypid, r1.business_name as Base_Listed_Name, r1.street_address as Base_Listed_Address, r1.city as Base_Listed_City, r1.state as Base_Listed_State, r1.zip5 as Base_Listed_Zip, rmve1.value as Base_URL,
r2.business_name as Google_Scanned_Listed_Name, r2.street_address as Google_Scanned_Listed_Address, r2.city as Google_Scanned_Listed_City, r2.state as Google_Scanned_Listed_City, r2.zip5 as Google_Scanned_Listed_Zip, rmve2.value as Google_Scanned_URL,
ls.presence_score, ls.listing_score,
case
when r1.business_name = r2.business_name then 'no_error'
else 'error'
end Business_Name_Status,
case
when r1.latitude = r2.latitude then 'no_error'
when r1.longitude = r2.longitude then 'no_error'
when r1.latitude is null or r1.latitude in ('0') then (case when r1.street_address = r2.street_address then 'no_error' else 'error' end)
else 'error'
end Street_Address_Status,
case
when r1.city = r2.city then 'no_error'
else 'error'
end City_Status,
case
when r1.state = r2.state then 'no_error'
else 'error'
end State_Status,
case
when r1.zip5 = r2.zip5 then 'no_error'
else 'error'
end Zip_Status,
case
when lower(replace(replace(replace(replace(replace(replace(rmve1.value, 'http://www.', null), 'www.', null), 'https://www.', null), 'http://', null), 'https://', null), 'wwww.', null))
= lower(replace(replace(replace(replace(replace(replace(rmve2.value, 'http://www.', null), 'www.', null), 'https://www.', null), 'http://', null), 'https://', null), 'wwww.', null)) then 'no_error'
else 'error'
end URL_Status
from mdm2.records r1 join mdm2.records r2 on r1.ypid = r2.ypid join mdm2.presence_listing_statuses ls on r1.ypid = ls.ypid
left outer join mdm2.record_mult_val_exts rmve1 on r1.id = rmve1.record_id and rmve1.extension_type = 'urls' and rmve1.value_type = 'primary'
left outer join mdm2.record_mult_val_exts rmve2 on r2.id = rmve2.record_id and rmve2.extension_type = 'urls' and rmve2.value_type = 'primary'
where r1.ypid in ('5625222','13846403','21974776','22806234','30303664','453728041')
and r1.source_code = 'PPA'
and r2.source_code = 'GOOG';
results
|YPID|BASE_LISTED_NAME|BASE_LISTED_ADDRESS|BASE_LISTED_CITY|BASE_LISTED_STATE|BASE_LISTED_ZIP|BASE_URL|GOOGLE_SCANNED_LISTED_NAME|GOOGLE_SCANNED_LISTED_ADDRESS|GOOGLE_SCANNED_LISTED_CITY|GOOGLE_SCANNED_LISTED_CITY_1|GOOGLE_SCANNED_LISTED_ZIP|GOOGLE_SCANNED_URL|PRESENCE_SCORE|LISTING_SCORE|BUSINESS_NAME_STATUS|STREET_ADDRESS_STATUS|CITY_STATUS|STATE_STATUS|ZIP_STATUS|URL_STATUS|
|5625222|Affinity Insurance Agency|5702 S Staples St Suite G|Corpus Christi|TX|78413|http://affinityia.com|Affinity Insurance Agency|5702 S Staples St Suite G|Corpus Christi|TX|78413|http://corpuschristiinsuranceprovider.com|90|97|no_error|no_error|no_error|no_error|no_error|error|
|13846403|Party Bazaar|4435 Lovers Ln|Dallas|TX|75225|www.partybazaardallas.com|Party Bazaar|4435 Lovers Ln|Dallas|TX|75225|http://partybazaardallas.com|93|100|no_error|no_error|no_error|no_error|no_error|no_error|
|21974776|Alterations To Go|2100 Arden Way Ste 150|Sacramento|CA|95825|http://www.alterationstogosacramento.com|Alterations To Go|2100 Arden Way # 150|Sacramento|CA|95825|http://alterations-togo.com|91|99|no_error|no_error|no_error|no_error|no_error|error|
|22806234|RV America|3640 Chambers Rd|Aurora|CO|80011|http://www.rvamericainc.com/pages/rv%20financing|RV America|3640 Chambers Rd|Aurora|CO|80011|http://rvamericainc.com|83|91|no_error|no_error|no_error|no_error|no_error|error|
|30303664|Sorelli Hair Studio & Spa|400 Saint Andrews Blvd|Melbourne|FL|32940|http://sorellihairstudio.com|Sorelli Hair Studio & Spa|400 Saint Andrews Blvd|Melbourne|FL|32940|http://sorellihairstudio.com|91|99|no_error|no_error|no_error|no_error|no_error|no_error|
|453728041|Carolina Driving School|534 Walkertown Guthrie Rd|Winston Salem|NC|27101|http://www.carolinadriving.com|Carolina Driving School|534 Walkertown Guthrie Rd|Winston Salem|NC|27101|http://carolinadrivingschool.com|87|97|no_error|no_error|no_error|no_error|no_error|error|
i guess you need to use LEAD , LAG function .
check this link http://oracle-base.com/articles/misc/lag-lead-analytic-functions.php
LAG function is used to access data from a previous row
LEAD function is used to return data from the next row.
by this you can compare 1st row with 2nd row
I am trying this query but found the error on &CLEARED_FLAG
ORA-00933: SQL command not properly ended
SELECT vch_locn_code
,vch_vch_type
,vch_vch_#
,vch_srl_#
,vch_bank_code
,vch_instrmt_type
,vch_instrmt_num
,vch_instrmt_date
,vch_instrmt_amt
,vch_drawn_at
,vch_payable_at
,vch_dshnr_flag
,vch_rcln_flag
,vch_rcln_date
,vch_trns_type
,vch_payee_name
,vch_bv_date
,vch_clear_date
,dd_no
,dd_dt
,cleared_dt
FROM fac_vch_bv
WHERE vch_bv_date BETWEEN :from_date AND :to_date
AND vch_locn_code = :locn_code
AND vch_vch_# IN (SELECT DISTINCT vch_vch_#
FROM fac_vch_d
WHERE vch_gl_code = :bank_code
AND vch_dbcr = (SELECT decode(:bank_receipt, 'Y', 'D', 'N', 'C') FROM dual)
AND vch_vch_type = '0102')
AND vch_vch_# IN (SELECT vch_vch_#
FROM fac_vch_m
WHERE vch_vch_type = '0102'
AND vch_bank_code = :bank_code) &cleared_flag
ORDER BY vch_instrmt_num
,vch_instrmt_date