PL-SQL: ORA-00904 - Invalid Identifier - Column in Select and Pivot Clause - sql

Have code that works to create output below, and cannot for the life of me debug the pivot to take "Tax Status" to each have their own column. I remove the "ORDER" and "GROUP" clauses and try this as a pivot, but it still yields "ORA-00904: "Tax Status": invalid identifier". Depending on what I've done it gets made at the initial select at times, others it gets angry about the pivot and if Im using single or double quotes.
Pivot Struggling With:
pivot
(
min('Total Value')
for ("Tax Status")
in ('Exempt from Taxation' as "Exempt", 'Taxable' as "Taxable", 'Tax Agreement - Operator of a Public Utility' as "Tax Agreement",
'"Assessed Person" Tax Agreement' as "Tax Agreement", 'Grant in Place of Tax' as "Grant", 'Council Tax Cancellation or Refund' as "Council Cancel/Refund")
)
Working Query that Produces Output Below:
SELECT "Team", "Tax Status", sum("Total Value") "Total Value"
FROM
(
select (A.account_roll_number) "Roll Number", ALU.DESCRIPTION "Assessor", A.account_total_property_value as "Total Value",
TaxLU.DESCRIPTION "Tax Status",
CASE
when A.assessor_id in ('ATHENDRATA', 'BRTHOMPSON', 'FTACIUNE', 'HPHILLIPS', 'JDCHU', 'JRYOUNG1', 'MHARTMANN', 'NCCHAN', 'RLEE5', 'SBERZINS') then 'Industrial'
when A.assessor_id in ('ASMTDWA','ASMTEB', 'ASMTWS', 'BBROCKLEBANK', 'CCHICHAK', 'CYMAU', 'GJONES4', 'IYPAU', 'JTGREER', 'KHOUSTON', 'LGMORRISON', 'MMCKENZIE1', 'MWALZ', 'SKUANG', 'STBAZIN', 'TKNGUYEN1', 'ASHIELDS') then 'Single Residential'
when A.assessor_id in ('BTANG', 'CMACMILLAN1', 'DGENCARELLI', 'EWU1', 'JWEHLER', 'LMDUNBAR', 'LWONG4', 'MGULOWSKA', 'RLEE1', 'SHAMMOUD', 'SLTURNER', 'YWANG') then 'Multi Residential'
when A.assessor_id in ('CMULENGA', 'EPOPOVICS', 'GFULLER', 'IMCDERMOTT', 'JERMUBE', 'JNSTEVENSON', 'JPLEPINE', 'KBUCKRY', 'KDALMHJELL', 'NPHAM1', 'PGKERSEY', 'SMSAMPLE') then 'Special Purpose and Land'
when A.assessor_id in ('ASMTHN', 'DCARSON', 'DLIDGREN', 'DMCCORD', 'EBORISENKO', 'HYAU1', 'MCTRIMBLE', 'RJTHARAKAN', 'TBJOHNSON1', 'VWONG1', 'WGIBBS', 'YYE', 'AVPETERS') then 'Office'
when A.assessor_id in ('AKEAST', 'BLTHOMPSON', 'BNELSON1', 'JCRUJI', 'JWONG1', 'KGARDINER', 'KMHAUT', 'NTNGUYEN', 'RTLUCHAK', 'SGILL3', 'THEGER1', 'TJLUDLOW', 'ZRGEIB') then 'Retail'
else 'Other'
END as "Team"
from REP_DBA.AB000_ACCOUNT A
join REP_DBA.LU_ASMT_ASSIGN_ASSESSOR ALU
on A.assessor_id = ALU.code
-- Decode the Tax Status from the LU Table
join rep_dba.LU_ASMT_ACCT_TAX_STATUS TaxLU
on TaxLU.CODE = A.account_tax_status
where A.rollyear = :rollyear
and A.account_type = 'P'
and A.account_status = 'AP'
and A.account_total_property_value is not null
ORDER BY account_total_property_value DESC
)
GROUP BY "Team", "Tax Status"
ORDER BY "Team"
Output before Pivot

You must use double quotes for the column in PIVOT as follows:
Select * from
(
SELECT "Team", "Tax Status", sum("Total Value") "Total Value"
FROM
(
select (A.account_roll_number) "Roll Number", ALU.DESCRIPTION "Assessor", A.account_total_property_value as "Total Value",
TaxLU.DESCRIPTION "Tax Status",
CASE
when A.assessor_id in ('ATHENDRATA', 'BRTHOMPSON', 'FTACIUNE', 'HPHILLIPS', 'JDCHU', 'JRYOUNG1', 'MHARTMANN', 'NCCHAN', 'RLEE5', 'SBERZINS') then 'Industrial'
when A.assessor_id in ('ASMTDWA','ASMTEB', 'ASMTWS', 'BBROCKLEBANK', 'CCHICHAK', 'CYMAU', 'GJONES4', 'IYPAU', 'JTGREER', 'KHOUSTON', 'LGMORRISON', 'MMCKENZIE1', 'MWALZ', 'SKUANG', 'STBAZIN', 'TKNGUYEN1', 'ASHIELDS') then 'Single Residential'
when A.assessor_id in ('BTANG', 'CMACMILLAN1', 'DGENCARELLI', 'EWU1', 'JWEHLER', 'LMDUNBAR', 'LWONG4', 'MGULOWSKA', 'RLEE1', 'SHAMMOUD', 'SLTURNER', 'YWANG') then 'Multi Residential'
when A.assessor_id in ('CMULENGA', 'EPOPOVICS', 'GFULLER', 'IMCDERMOTT', 'JERMUBE', 'JNSTEVENSON', 'JPLEPINE', 'KBUCKRY', 'KDALMHJELL', 'NPHAM1', 'PGKERSEY', 'SMSAMPLE') then 'Special Purpose and Land'
when A.assessor_id in ('ASMTHN', 'DCARSON', 'DLIDGREN', 'DMCCORD', 'EBORISENKO', 'HYAU1', 'MCTRIMBLE', 'RJTHARAKAN', 'TBJOHNSON1', 'VWONG1', 'WGIBBS', 'YYE', 'AVPETERS') then 'Office'
when A.assessor_id in ('AKEAST', 'BLTHOMPSON', 'BNELSON1', 'JCRUJI', 'JWONG1', 'KGARDINER', 'KMHAUT', 'NTNGUYEN', 'RTLUCHAK', 'SGILL3', 'THEGER1', 'TJLUDLOW', 'ZRGEIB') then 'Retail'
else 'Other'
END as "Team"
from REP_DBA.AB000_ACCOUNT A
join REP_DBA.LU_ASMT_ASSIGN_ASSESSOR ALU
on A.assessor_id = ALU.code
-- Decode the Tax Status from the LU Table
join rep_dba.LU_ASMT_ACCT_TAX_STATUS TaxLU
on TaxLU.CODE = A.account_tax_status
where A.rollyear = :rollyear
and A.account_type = 'P'
and A.account_status = 'AP'
and A.account_total_property_value is not null
-- ORDER BY account_total_property_value DESC -- not needed
)
GROUP BY "Team", "Tax Status"
)
pivot
(
min("Total Value") -- here
for ("Tax Status")
in ('Exempt from Taxation' as "Exempt", 'Taxable' as "Taxable",
'Tax Agreement - Operator of a Public Utility' as "Tax Agreement", -- duplicate
'"Assessed Person" Tax Agreement' as "Tax Agreement 1", -- changed alias, added 1
'Grant in Place of Tax' as "Grant", 'Council Tax Cancellation or Refund' as "Council Cancel/Refund")
)
Cheers!!

Related

Error "No column name was specified for column " " of "SOURCE" while select with case on merge

I am trying to select with case on merge in one of my pet projects and I ended up getting error.
I believe this is not the complete query, it is huge in number of lines and I can copy only this from the terminal. I thought maybe someone could help with this code and resolve my issue.
MERGE OrderDetails AS TARGET
USING
(
SELECT OrderHeader.OrderNo, SalesOrderData.[LineNo], SalesOrderData.WebOrderNo, SalesOrderData.quantity,ISNULL(SalesOrderData.BasePrice,'0') AS BasePrice,ISNULL(SalesOrderData.CustomPrice,'0') AS CustomPrice,
ISNULL(SalesOrderData.FinishingPrice,'0')AS FinishingPrice,ISNULL(SalesOrderData.NonDiscount2,'0') AS NonDiscountable, ISNULL(SalesOrderData.TotalPrice,'0') AS TotalPrice,
ISNULL(SalesOrderData.ExtendedPrice,'0') As ExtendedPrice,SalesOrderData.Category,SalesOrderData.StockNo,SalesOrderData.SSD,SalesOrderData.VerticalSS,SalesOrderData.LorH, SalesOrderData.WorB, SalesOrderData.Species,
SalesOrderData.FinishingOption, SalesOrderData.Grade, SalesOrderData.Sheen, SalesOrderData.FinishingBrand,SalesOrderData.ColorName,SalesOrderData.ColorNo,SalesOrderData.StockPaint,
CASE
WHEN SalesOrderData.Category = 'TL' THEN '1.125'
WHEN SalesOrderData.Category = 'RP' THEN '1.125'
WHEN SalesOrderData.Category = 'CTL' THEN '1.25'
WHEN SalesOrderData.Category = 'CTL-BAH' THEN '1.25'
WHEN SalesOrderData.Category = 'CRP' THEN '1.25'
WHEN SalesOrderData.Category = 'IRP' THEN '1.07'
Else SalesOrderData.[SS Thickness]
END
, SalesOrderData.BRD, SalesOrderData.TRD, SalesOrderData.CRD, SalesOrderData.CRD2, SalesOrderData.CRD3, SalesOrderData.CRP1,SalesOrderData.CRP2, SalesOrderData.CRP3, SalesOrderData.Section1, SalesOrderData.Section2,
SalesOrderData.Section3, SalesOrderData.Section4,
CASE
WHEN SalesOrderData.PanelType = 'NA' THEN '-'
Else SalesOrderData.PanelType
END
FROM SalesOrderData
INNER JOIN OrderHeader ON SalesOrderData.WebOrderNo = OrderHeader.WebOrderNo
INNER JOIN OrderDetails ON SalesOrderData.WebOrderNo = OrderDetails.WebOrderNo)
AS SOURCE
ON Source.WebOrderNo = Target.WebOrderNo
WHEN NOT MATCHED BY TARGET
THEN
INSERT
(OrderNo, [LineNo], WebOrderNo, Quantity,BasePrice, CustomPrice, FinishingPrice, NonDiscountable,TotalPrice,ExtendedPrice, Category,StockNo, SSD, VerticalSS,LorH, WorB, Species,FinishingOption, Grade, Sheen,
FinishingBrand, ColorName,ColorNo,StockPaint,SSthick, BRD, TRD, CRD, CRD2, CRD3, CRP1Req,CRP2Req, CRP3Req, Section1, Section2, Section3, Section4,PanelType, RailConfig, ItemText6,SStype, ArchLow, ArchHigh,
LouverDirection, TrimType, TrimLouverDirection,MHLouverDirection, FCRLouverDirection,MHTR,MHCR1,MHCR2,MHCR3,UM,VBoardWidth, VBoardTotal, HBoardWidth,VBoardSpacing,ShutterComments,Custom1,Custom2,Custom3,Custom4,Custom5)
VALUES
(Source.OrderNo,Source.[LineNo], Source.WebOrderNo, Source.Quantity,Source.BasePrice, Source.CustomPrice, Source.FinishingPrice, Source.NonDiscountable,Source.TotalPrice,Source.Source.ExtendedPrice, Source.Category,
Source.StockNo, Source.SSD, Source.VerticalSS,Source.LorH, Source.WorB, Source.Species, Source.FinishingOption, Source.Grade, Source.Sheen, Source.FinishingBrand, Source.ColorName,Source.ColorNo,Source.StockPaint,
Source.SSthick, Source.BRD, Source.TRD, Source.CRD, Source.CRD2, Source.CRD3, Source.CRP1Req,Source.CRP2Req, Source.CRP3Req, Source.Section1, Source.Section2, Source.Section3, Source.Section4,Source.PanelType,
Source.RailConfig, Source.ItemText6,Source.SStype, Source.ArchLow, Source.ArchHigh, Source.LouverDirection, Source.TrimType, Source.TrimLouverDirection,Source.MHLouverDirection, Source.FCRLouverDirection,Source.MHTR,
Source.MHCR1,Source.MHCR2,Source.MHCR3,Source.UM,Source.VBoardWidth, Source.VBoardTotal, Source.HBoardWidth,Source.VBoardSpacing,SSource.hutterComments,Source.Custom1,Source.Custom2,Source.Custom3,Source.Custom4,
Source.Custom5);
Your CASE expressions need aliases. You have, for example:
CASE
WHEN SalesOrderData.Category = 'TL' THEN '1.125'
...
ELSE SalesOrderData.[SS Thickness]
END
,
It needs to be:
SomeMeaningfulAlias = CASE
WHEN SalesOrderData.Category = 'TL' THEN '1.125'
...
ELSE SalesOrderData.[SS Thickness]
END
,
Or:
CASE
WHEN SalesOrderData.Category = 'TL' THEN '1.125'
...
ELSE SalesOrderData.[SS Thickness]
END AS SomeMeaningfulAlias
,

Need SQL JOIN statement assistance

I am creating a report that needs to list both Primary Person Id and Alternate Person ID. But it also needs to show both Primary Person IDs contact information and Alternates. Report I've created right now only lists out Primary Person ID's contact information, but shows the Alternates ID number. Can someone assist me in fixing my sql so both Primary and Alternates contact information is listed and not just the Primary's. The sql I have is below.
SELECT "ORG_ACCOUNT".ACCOUNT_NUMBER AS "Account Number",
"ORG_PERSON".ADDRESS_2 AS "Address",
"ORG_ACCOUNT".DODAAC AS "Dodaac",
"ORG_DODAAC".DRA AS "Dra",
"ORG_PERSON".EMAIL AS "Email",
"ORG_PERSON".FIRST_NAME AS "First Name",
"ORG_PERSON".LAST_NAME AS "Last Name",
"ORG_PERSON".LAST_TRAIN_DATE AS "Last Train Date",
"ORG_PERSON".MIDDLE_NAME AS "Middle Name",
"ORG_ALT_ACCOUNT_CUST".PERSON_ID AS "Alt Person Id",
"ORG_ORG".ORG_NAME AS "Org Name",
"ORG_ACCOUNT".PERSON_ID AS "Person Id",
"ORG_PERSON".PHONE_COM AS "Phone Com",
"ORG_PERSON".PHONE_DSN AS "Phone Dsn",
"ORG_PERSON".RANK AS "Rank"
FROM "ORG"."ORG_ACCOUNT" "ORG_ACCOUNT",
"ORG"."ORG_DODAAC" "ORG_DODAAC",
"ORG"."ORG_ORG" "ORG_ORG",
"ORG"."ORG_PERSON" "ORG_PERSON"
"ORG"."ORG_ALT_ACCOUNT_CUST" "ORG_ALT_ACCOUNT_CUST"
WHERE ( ( "ORG_PERSON".PERSON_ID(+) = ORG_ALT_ACCOUNT_CUST".PERSON_ID )
AND ( "ORG_ORG".ORG_ID = "ORG_ACCOUNT".ORG_ID )
AND ( "ORG_PERSON".PERSON_ID = "ORG_ACCOUNT".PERSON_ID )
AND ( "ORG_ALT_ACCOUNT_CUST".PERSON_ID = "ORG_ACCOUNT".PERSON_ID )
AND ( "ORG_DODAAC".DODAAC = "ORG_ACCOUNT".DODAAC ) )
AND ( UPPER("ORG_ACCOUNT".DODAAC) LIKE UPPER(:DODAAC)
AND "ORG_DODAAC".DRA IN ( :P_DRA_ENTRIES)
AND UPPER("ORG_ACCOUNT".DODAAC_COMMODITY) = UPPER('A') )
ORDER BY "ORG_DODAAC".DRA ASC, "ORG_ACCOUNT".ACCOUNT_NUMBER ASC, "ORG_PERSON".LAST_NAME ASC
When you want to join a table twice, like you do here with ORG_PERSON, you need to list it twice in the FROM clause (with different aliases).
SELECT ORG_ACCOUNT.ACCOUNT_NUMBER AS "Account Number",
ORG_PERSON.ADDRESS_2 AS "Address",
ORG_ACCOUNT.DODAAC AS "Dodaac",
ORG_DODAAC.DRA AS "Dra",
ORG_PERSON.EMAIL AS "Email",
ORG_PERSON.FIRST_NAME AS "First Name",
ORG_PERSON.LAST_NAME AS "Last Name",
ORG_PERSON.LAST_TRAIN_DATE AS "Last Train Date",
ORG_PERSON.MIDDLE_NAME AS "Middle Name",
ORG_ALT_ACCOUNT_CUST.PERSON_ID AS "Alt Person Id",
ORG_ORG.ORG_NAME AS "Org Name",
ORG_ACCOUNT.PERSON_ID AS "Person Id",
ORG_PERSON.PHONE_COM AS "Phone Com",
ORG_PERSON.PHONE_DSN AS "Phone Dsn",
ORG_PERSON.RANK AS "Rank",
alt_person.address_2 as "Alt Address",
alt_person.email as "Alt Email",
alt_person.first_name as "Alt First Name",
alt_person.last_name as "Alt Last Name",
alt_person.phone_com as "Alt Phone"
FROM "ORG".ORG_ACCOUNT ORG_ACCOUNT,
"ORG".ORG_DODAAC ORG_DODAAC,
"ORG".ORG_ORG ORG_ORG,
"ORG".ORG_PERSON ORG_PERSON
"ORG".ORG_ALT_ACCOUNT_CUST ORG_ALT_ACCOUNT_CUST,
"ORG".ORG_PERSON alt_person
WHERE ( ( alt_person.PERSON_ID(+) = ORG_ALT_ACCOUNT_CUST.PERSON_ID )
AND ( ORG_ORG.ORG_ID = ORG_ACCOUNT.ORG_ID )
AND ( ORG_PERSON.PERSON_ID = ORG_ACCOUNT.PERSON_ID )
AND ( ORG_ALT_ACCOUNT_CUST.PERSON_ID = ORG_ACCOUNT.PERSON_ID )
AND ( ORG_DODAAC.DODAAC = ORG_ACCOUNT.DODAAC ) )
AND ( UPPER(ORG_ACCOUNT.DODAAC) LIKE UPPER(:DODAAC)
AND ORG_DODAAC.DRA IN ( :P_DRA_ENTRIES)
AND UPPER(ORG_ACCOUNT.DODAAC_COMMODITY) = UPPER('A') )
ORDER BY ORG_DODAAC.DRA ASC, ORG_ACCOUNT.ACCOUNT_NUMBER ASC, ORG_PERSON.LAST_NAME ASC
Some style notes: I removed the double quotes from your table names and aliases because they're annoying and unnecessary. But I left your query in the old proprietary Oracle join syntax instead of ANSI joins, since I know a lot of workplaces still use it as an internal coding standard. I left my changes in lowercase so they'd be easy to see.

Outputting XML to file

I am brand new to XML as well as SQL procedures, and I am trying to get this to output to a .txt (or .xml?) on one of our UNIX server. I have been looking at various things online, but having trouble getting it right. Could someone push me in the right direction?
create or replace procedure markviewimport_interface (p_invoice_id number(10), p_filename nvarchar(30))
is
v_output clob;
begin
SELECT
XMLFOREST(
XMLCONCAT(
XMLELEMENT("CREATEDBY",XMLATTRIBUTES('Exported By' AS "header"), 'Magellan IT'),
XMLELEMENT("TIMESTAMP",XMLATTRIBUTES('Date' AS "header"), TO_CHAR(SYSDATE,'MM.DD.YYYY')),
XMLFOREST(
XMLFOREST(
XMLFOREST(
'invoice_id' AS "DBFIELD",
'Invoice ID' AS "CAPTION",
r_markviewimport.invoice_id AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'vendor_num' AS "DBFIELD",
'Vendor Num' AS "CAPTION",
r_markviewimport.vendor_num AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'vendor_name' AS "DBFIELD",
'Vendor Name' AS "CAPTION",
r_markviewimport.vendor_name AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'po_number' AS "DBFIELD",
'PO Number' AS "CAPTION",
r_markviewimport.po_number AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'invoice_date' AS "DBFIELD",
'Invoice Date' AS "CAPTION",
r_markviewimport.invoice_date AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'invoice_num' AS "DBFIELD",
'Invoice Number' AS "CAPTION",
r_markviewimport.invoice_num AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'terms_name' AS "DBFIELD",
'Terms Date' AS "CAPTION",
r_markviewimport.terms_name AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'invoice_amount' AS "DBFIELD",
'Invoice Amount' AS "CAPTION",
r_markviewimport.invoice_amount AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'amount_applicable_to_discount' AS "DBFIELD",
'Amount Applicable to Discount' AS "CAPTION",
r_markviewimport.amount_applicable_to_discount AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'amount_paid' AS "DBFIELD",
'Amount Paid' AS "CAPTION",
r_markviewimport.amount_paid AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'payment_date' AS "DBFIELD",
'Payment Date' AS "CAPTION",
r_markviewimport.payment_date AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'filename' AS "DBFIELD",
'File Name' AS "CAPTION",
r_markviewimport.filename AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'complete_filename' AS "DBFIELD",
'Complete File Name' AS "CAPTION",
r_markviewimport.complete_filename AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'document_id' AS "DBFIELD",
'Document ID' AS "CAPTION",
r_markviewimport.document_id AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'text' AS "DBFIELD",
'Text' AS "CAPTION",
r_markviewimport.text AS "VALUE"
) AS "DATA_ITEM",
XMLFOREST(
'tool_name' AS "DBFIELD",
'Tool Name' AS "CAPTION",
r_markviewimport.tool_name AS "VALUE"
) AS "DATA_ITEM"
) AS "BASICDATA"
)
) AS "DATA_ROOT"
) .getclobval() into v_output
FROM
(
SELECT DISTINCT inv.invoice_id,
vendor.segment1 vendor_num,
vendor.vendor_name,
poh.segment1 po_number,
inv.invoice_date,
inv.invoice_num,
terms.name terms_name,
inv.invoice_amount,
inv.amount_applicable_to_discount,
inv.amount_paid,
pmt.check_date payment_date,
path.filename,
path.complete_filename,
path.document_id,
stamps.text,
stamps.tool_name
FROM apps.ap_invoices_all inv,
apps.ap_invoice_distributions_all dist,
apps.po_distributions_all podi,
apps.ap_invoice_payment_history_v pmt,
apps.fnd_attached_docs_form_vl fnd,
markview.mv_page_image_paths path,
apps.po_vendors vendor,
apps.po_headers_all poh,
apps.ap_terms terms,
(
SELECT mp.document_id,
moi.markup_object_id,
moi.page_markups_view_id,
moi.text,
mvt.tool_name,
mp.page_id
FROM markview.mv_markup_object moi,
markview.mv_tool mvt,
markview.mv_page_markups_view mpmv,
markview.mv_page mp
WHERE moi.tool_id = mvt.tool_id
AND mp.page_id = mpmv.page_id
AND mpmv.page_markups_view_id = moi.page_markups_view_id
AND mvt.tool_id IN
(
SELECT mvt.tool_id
FROM markview.mv_tool
WHERE mvt.tool_name IN ( 'Green Text',
'Blue Sticky Note' ) )) stamps
WHERE inv.invoice_id = to_number(fnd.pk1_value)
AND inv.invoice_id = dist.invoice_id
AND poh.po_header_id(+) = podi.po_header_id
AND podi.po_distribution_id(+) = dist.po_distribution_id
AND fnd.file_name = to_char(path.document_id)
AND inv.invoice_id = pmt.invoice_id
AND path.document_id = stamps.document_id(+)
AND path.page_id = stamps.page_id(+)
AND fnd.category_description = 'MarkView Document'
AND fnd.entity_name = 'AP_INVOICES'
AND inv.vendor_id = poh.vendor_id(+)
AND inv.terms_id = terms.term_id
AND inv.vendor_id = vendor.vendor_id
AND path.platform_name = 'UNIX_FS_TO_DOC_SERVER'
AND pmt.void = 'N'
--AND inv.invoice_id = 4796324
DBMS_XSLPROCESSOR.clob2file(v_output, 'My Directory', 'output.xml');
) r_markviewimport
Here is my procedure, where am I going wrong?
Thanks!

PostgreSQL - How can I return results from multiple field IDs?

I would like to rewrite this query so I can return results from four field IDs: industry, location, phone number, SFDC contact ID.
At the bottom, you will see I commented out the other columns I would like to surface. Due to the way this is currently written, I can only show one at a time, and have to uncomment/comment accordingly. An important consideration is to write this so it shows all records available for industry, or location, or phone number, or SFDC contact ID (as opposed to only show records where data is available across the board through an implied "and").
As a bonus, the phone number value does include the type. Any way to remove that? For example: "123-456-7890|work" ...I would just want this to be "123-456-7890" but worst case, I can always remove this in Excel.
I appreciate any help with this.
select cmsuser.userid as "User ID",
cmsuser.username as "Username",
cmsuser.firstname as "First Name",
cmsuser.lastname as "Last Name",
cmsuser.email as "Email",
cmsuser.userenabled as "Enabled?",
to_char(date(to_timestamp(cmsuser.creationdate/1000)),'YYYY-MM-DD') as "Creation Date",
to_char(date(to_timestamp(cmsuser.modificationdate/1000)),'YYYY-MM-DD') as "Modification Date",
to_char(date(to_timestamp(cmsuser.lastloggedin/1000)),'YYYY-MM-DD') as "Last Logged In",
to_char(date(to_timestamp(cmsuser.lastprofileupdate/1000)),'YYYY-MM-DD') as "Last Profile Update",
---****** Industry ******
cmsuserprofile.value as "Industry"
from cmsuser, cmsuserprofile
where cmsuser.userid = cmsuserprofile.userid and cmsuserprofile.fieldid = '5011' and cmsuser.userenabled = '1';
---****** Location ******
---cmsuserprofile.value as "Location"
---from cmsuser, cmsuserprofile
---where cmsuser.userid = cmsuserprofile.userid and cmsuserprofile.fieldid = '6' and cmsuser.userenabled = '1';
---****** Phone Number ******
---cmsuserprofile.value as "Phone Number"
---from cmsuser, cmsuserprofile
---where cmsuser.userid = cmsuserprofile.userid and cmsuserprofile.fieldid = '1' and cmsuser.userenabled = '1';
---****** SFDC Contact ID ******
---cmsuserprofile.value as "SFDC Contact ID"
---from cmsuser, cmsuserprofile
---where cmsuser.userid = cmsuserprofile.userid and fieldid = '5004' and cmsuser.userenabled = '1';
select
u.userid as "User ID",
u.username as "Username",
u.firstname as "First Name",
u.lastname as "Last Name",
u.email as "Email",
u.userenabled as "Enabled?",
to_char(date(to_timestamp(u.creationdate/1000)),'YYYY-MM-DD') as "Creation Date",
to_char(date(to_timestamp(u.modificationdate/1000)),'YYYY-MM-DD') as "Modification Date",
to_char(date(to_timestamp(u.lastloggedin/1000)),'YYYY-MM-DD') as "Last Logged In",
to_char(date(to_timestamp(u.lastprofileupdate/1000)),'YYYY-MM-DD') as "Last Profile Update",
(select p.value from cmsuserprofile p where u.userid = p.userid and p.fieldid = '5011') as "Industry",
(select p.value from cmsuserprofile p where u.userid = p.userid and p.fieldid = '6') as "Location",
(select p.value from cmsuserprofile p where u.userid = p.userid and p.fieldid = '1') as "Phone Number",
(select p.value from cmsuserprofile p where u.userid = p.userid and p.fieldid = '5004') as "SFDC Contact ID"
from cmsuser u where u.userenabled = '1';

Put a "(" and ")" on string of sqlquery

string sqlquery=
Select userPropID , PropType, PropLoc, PropTranType,PropFloorNo From dbo.tbl_allProperties
WHERE PostPropFor = 'Sale' AND PropCity = '4320-1001041'
AND PropType ='Business Centre' OR PropType ='Space in Shopping Mall' OR PropType ='Commercial Showroom' AND PropImage !='~/user_prop_images/noImage.jpg'
Above sqlquery does not have fix field, it may expand with more fields as user enters value into fields/controls.
My requirement is :
if there is a single 'PropType', do nothing.
if more than one 'PropType', put a '(' before first 'PropType' and
a ')' after the value of last 'PropType'.
Above query should be like this:
Select userPropID , PropType, PropLoc, PropTranType,PropFloorNo From dbo.tbl_allProperties
WHERE PostPropFor = 'Sale' AND PropCity = '4320-1001041'
AND (PropType ='Business Centre' OR PropType ='Space in Shopping Mall' OR PropType ='Commercial Showroom') AND PropImage !='~/user_prop_images/noImage.jpg'
Your description modifies the values on separate rows. If so, you can use row_number() and a case statement:
Select userPropID,
(case when row_number() over (partition by userPropId order by PropTYpe) = 1 then '(' + PropType
when row_number() over (partition by userPropId order by PropTYpe desc) = 1 then PropType + ')'
else PropType
end) as PropType
PropLoc, PropTranType, PropFloorNo
From dbo.tbl_allProperties
where PostPropFor = 'Sale' AND PropCity = '4320-1001041' AND
PropType in ('Business Centre', 'Space in Shopping Mall', 'Commercial Showroom') AND
PropImage !='~/user_prop_images/noImage.jpg';