Derived Column in Query

Can somebody help me with this syntax? I am taking two working
queries and putting them together such that one becomes a
derived column in the other. I am guessing that I must just be
missing some small syntax point (I don't use Oracle much)
because this query runs fine in a SQL Server. I thought I had
gotten all the syntax converted, but I'm getting an error: "ORA-
00936: Missing Expression". Here's the statement:
SELECT A.CNTRCT_ID, A.VENDOR_ID,
(Select X.XLATSHORTNAME
From Sysadm.XLATTABLE X
WHERE X.EFFDT =
( SELECT MAX(EFFDT)
FROM Sysadm.XLATTABLE
WHERE X.FIELDNAME = FIELDNAME AND X.LANGUAGE_CD =
LANGUAGE_CD AND X.FIELDVALUE = FIELDVALUE
AND EFFDT <= TO_DATE('12/26/2001','MM-DD-YY')
And X.FIELDNAME = 'CNTRCT_STATUS' And X.FIELDVALUE=
A.CNTRCT_STATUS
) as StatusExtended,
A.CNTRCT_BEGIN_DT, A.CNTRCT_EXPIRE_DT, A.DESCR, B.NAME1
FROM Sysadm.PS_CNTRCT_HDR A, Sysadm.PS_VENDOR B
WHERE A.Z_PURCH_DOC_TYPE = 'B' AND A.CNTRCT_STATUS <> 'C' AND
B.VENDOR_ID = A.VENDOR_ID AND B.SETID = A.VENDOR_SETID
AND A.CNTRCT_EXPIRE_DT BETWEEN TO_DATE('12/26/2001','MM/DD/YY')
AND TO_DATE('1/25/2002','MM/DD/YY')
Order By B.NAME1
Thanks for your help!

Your code runs O.K. in Oracle 8.1.7.  I don't have 8.0.4 to test
it on, but I suggest you try re-writing it something like below,
and see if it works:
SELECT   A.CNTRCT_ID,
         A.VENDOR_ID,
         A.CNTRCT_BEGIN_DT,
         A.CNTRCT_EXPIRE_DT,
         A.DESCR,
         B.NAME1,
         c.xlatshortname AS StatusExtended
FROM     sysadm.PS_CNTRCT_HDR A,
         sysadm.PS_VENDOR B,
         (Select X.XLATSHORTNAME, x.fieldvalue
          From   sysadm.XLATTABLE X
          WHERE  X.EFFDT =
                 (SELECT MAX (EFFDT)
                  FROM   sysadm.XLATTABLE
                  WHERE  X.FIELDNAME = FIELDNAME
                  AND    X.LANGUAGE_CD = LANGUAGE_CD
                  AND    X.FIELDVALUE = FIELDVALUE
                  AND    EFFDT <=
                         TO_DATE ('12/26/2001', 'MM/DD/YYYY'))
          And    X.FIELDNAME = 'CNTRCT_STATUS') c
WHERE    A.Z_PURCH_DOC_TYPE = 'B'
AND      A.CNTRCT_STATUS <> 'C'
AND      B.VENDOR_ID = A.VENDOR_ID
AND      B.SETID = A.VENDOR_SETID
AND      A.CNTRCT_EXPIRE_DT
         BETWEEN TO_DATE ('12/26/2001', 'MM/DD/YYYY')
         AND     TO_DATE ('01/25/2002', 'MM/DD/YYYY')
And      c.FIELDVALUE = A.CNTRCT_STATUS
Order By B.NAME1

Similar Messages

  • Convert SQL Query to Derived Column Expression

    I'm in the process of reworking some SSIS packages I inherited. A lot of these use Execute SQL Statement components to update certain fields in the tables once they've been loaded. I'd like to replace these individual UPDATE statements with Derived Column
    components.
    I've got 95% of them converted, except for a couple, one of which has me a bit perplexed and was hoping someone could provide some insight.
    Essentially, there is a column called POSTPERIOD which is a date in string format YYYYMM (i.e., 201503). The SQL update parses out the month piece and converts it to the month name and populates a column called POSTPERIOD_MONTH.
    Here is the SQL:
    select DateName(month , DateAdd(month, CONVERT(INT, SUBSTRING(POST_PERIOD,5,2)), 0 ) - 1 )
    I'd like to accomplish this using a Derived Column, but not sure how to go about doing this...
    If someone could point me in the right direction, it would be greatly appreciated!
    Thanks!
    A. M. Robinson

    Visakh:
    Thank you for the reply! I've tried your solution but am getting the following error(s):
    Warning 17 Validation warning. Populate STAGING_DIM_AP_DETAIL - RADIO: {ACAA99C4-272C-4641-BF44-B4D4409D1EFB}: The expression "(DT_STR,8,1252)((DT_I4)[SUBSTRING](#85,5,2) == 1 ? (DT_STR,8,1252)"January" : ((DT_I4)[SUBSTRING](#85,5,2)
    == 2 ? (DT_STR,8,1252)"February" : ((DT_I4)[SUBSTRING](#85,5,2) == 3 ? (DT_STR,8,1252)"March" : ((DT_I4)[SUBSTRING](#85,5,2) == 4 ? (DT_STR,8,1252)"April" : ((DT_I4)[SUBSTRING](#85,5,2) == 5 ? (DT_STR,8,1252)"May" :
    ((DT_I4)[SUBSTRING](#85,5,2) == 6 ? (DT_STR,8,1252)"June" : ((DT_I4)[SUBSTRING](#85,5,2) == 7 ? (DT_STR,8,1252)"July" : ((DT_I4)[SUBSTRING](#85,5,2) == 8 ? (DT_STR,8,1252)"August" : ((DT_I4)[SUBSTRING](#85,5,2) == 9 ? (DT_STR,8,1252)"September"
    : ((DT_I4)[SUBSTRING](#85,5,2) == 10 ? (DT_STR,8,1252)"October" : ((DT_I4)[SUBSTRING](#85,5,2) == 11 ? (DT_STR,8,1252)"November" : (DT_STR,8,1252)"December")))))))))))" will always result in a truncation of data. The expression
    contains a static truncation (the truncation of a fixed value).   Dimension Finance - Load STAGING_DIM_AP_DETAIL_DERIVED_COLUMNS.dtsx 0 0 
    This is the derived column expression I'm using:
    (DT_STR,8,1252) ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 1? (DT_STR,8,1252) "January" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 2 ? (DT_STR,8,1252) "February" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 3 ? (DT_STR,8,1252) "March" :((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 4 ? (DT_STR,8,1252) "April":((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 5 ? (DT_STR,8,1252) "May" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 6 ? (DT_STR,8,1252) "June" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 7 ? (DT_STR,8,1252) "July" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 8 ? (DT_STR,8,1252) "August":((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 9 ? (DT_STR,8,1252) "September":((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 10? (DT_STR,8,1252) "October": ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 11 ? (DT_STR,8,1252) "November" : (DT_STR,8,1252)"December")))))))))))
    Some info that might be of some help in the matter...the POST_PERIOD field is a VARCHAR(8), the POST_PERIOD_MONTH field is also a VARCHAR(8).
    There is a computed column Any help would be appreciated once again!!!
    A. M. Robinson

  • Problem with derived column

    Hi friends,
    [Reports 6i - 6.0.8.20.1 & DB 9.2.0.8 ]
    I have problems in one report to rerieve the value of a column in my Query1 in a derived column.
    Let's say that we have a query (Q1) that obtain the departments of a company.
    And a second query that obtain certain data for each department of Q1 and (this is important) we can't (due to others requirements) use a "link" to join the querys.
    So my idea was to create a formula column (FC1) in Q1 where the departement is stored... and, out of the query, create a derived column that would have the value of FC1.
    Then ... in design model... I'll have 2 repeating frames... one based on Q1 and other based on Q2..
    Q1 Frame is ok and shows all departments... but... Q2 repeating... only shows values for 1 department... So my derived column seems not to change when the value of FC1 changes...
    Any ideas?
    Thanks,
    Jose

    If your query1 is something like
    SELECT ...
    d.deptno,
    FROM
    ...dept d
    WHERE ...
    and you want to do query2
    SELECT ...
    FROM ...
    for all departments but then split the output on display by department.
    I'd go with the suggestion from the other poster above:
    Do your query1 as
    SELECT ...Query1Fields,
    Query2Fields
    FROM Query1Tables, (put query2 here) q2
    where q2.deptno = dept.deptno -- or whatever the conditions are
    Or use
    WITH q2 AS (put query2 here)
    SELECT ...Query1Fields,
    Query2Fields
    FROM Query1Tables, q2
    where q2.deptno = dept.deptno -- or whatever the conditions are
    That second format should ensure that query2 is done as one whole unit.
    Then in the data model drag and drop the query2fields outside the query1 group to form a new group below it. Then in the layout you have a repeating group based on the query1 group and within it a repeating group based on the new "query2" group.

  • Change Date-Time format through derived column

    Hi,
    I have Date in MM-DD-YYYY Format & Want to convert it to
    YYYY-MM-DD format through derived column. Can anyone help with the expression required for the conversion.???
    Thanks.

    Adarsh,
    check the below modified one ..
    I have my OLEDB source query as :
    select convert(varchar(10),getdate(),101) as date_var
    My Expression used in the Derived Column part is :
    SUBSTRING((DT_WSTR,100)date_var,7,4) + "-" + SUBSTRING((DT_WSTR,100)date_var,1,2) + "-" + SUBSTRING((DT_WSTR,100)date_var,4,2)
    (It works irrespective of whther it is a DATE/DATETIME type or STRING type .. )
    Hope that helps!!
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Finding correlation using derived columns?

    I want to use the aggregate CORR_S function which take two numerical columns and output the correlation between them. Assuming I have the table:
    Employee(name, gender, salary) where I want to create two derived columns, how would I do it?
    Like,
    SELECT CORR_S(
    SELECT salary
    FROM employees
    WHERE salary < 10000,
    SELECT salary
    FROM employees
    WHERE salary > 10000
    ) as correlation
    FROM employees
    It will find the correlation between salary's less than $10,000 in one column and salary's more than $10,000 in another column. Of course, I get an error when running the query. It's no problem if I use CORR_S(salary, salary) but I want to use derived columns, is it possible? Or, will I need to create a new table view with two new columns CORR_S(lowSalary, highSalary)?
    Thanks.

    It may be correct sql query, but statistically ( i mean here the OP question, or at least how i interpret it) it is nonsense.
    Clearly , correlation show how good distribution of one set of items corresponds to another set, so the order of item in the itemset does matter. Consider
    SQL> WITH t AS (
      2          SELECT 1 id1, 10 id2, 30 id3 FROM dual UNION ALL
      3          SELECT 2 , 20 , 10 FROM dual UNION ALL
      4          SELECT 3 , 30 , 20 FROM dual )
      5  SELECT corr_s(id1,id2), corr_s(id1,id3)
      6  FROM t
      7  /
    CORR_S(ID1,ID2) CORR_S(ID1,ID3)
                  1             -.5So, it would make sense to calculate correlation between salary and hiredate, salary and department number, salary and employee name's length, whatever, but how can be correlated salary less 10k to salary more than 10k - i can't understand it. They are not in the same set, but in two different sets ( while one can have either more 10k or less 10k, but not both) and relation between these two sets is not given by OP.
    Best regards
    Maxim

  • Having issue Grouping by Derived Column

    I have a query with a derived column defined as such:
    CASE
                      WHEN (charindex('-', E1.Identification) - 1) <= 0 THEN
                        E1.Identification
                      ELSE
                        substring(E1.Identification, 1, charindex('-', E1.Identification) - 1)
                    END AS Group_nbr
    But if I try to use Group_nbr in a Group By clause it fails with an invalid column name. I thought for sure I've done this before.
    Thanks in Advance.

    SELECT logically performs after GROUP BY clause thus  you could not use this query because SQL Serveris not seen yet group_nbr column 
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Derived Column

    I'm getting the following error when I try to add a derived column or a link to a report region having a type of PL/SQL Function Body Returning SQL Query)
    failed to parse SQL query:
    ORA-00904: "COL60": invalid identifier
    Any ideas?
    Thanks
    David

    David,
    You’re using generic column names. This setting generates 60 generic columns, and 60 columns is the maximum number of columns allowed. Adding a derived column or link column exceeds that number. So these types of column can’t be used with generic column based reports. Try enabling the “use query specific column names” option when editing your report source. This type of report would allow adding link columns and derived columns.
    Regards,
    Marc

  • Derived column source

    I have a report based on a SQL query. In this query I have some IDs which are foreign keys from other tables. I want to hide these IDs and show the names from the IDs primary table. In oracle reports I can show this as a formula column with a source as a pl/sql function. Can this be done in htmldb with derived columns, if yes where I should write the pl/sql expression?
    I know I can do this by joining the table in the main query , but eager to know the other way is possible or not?
    Recently no one answering any of my questions . Is there anything wrong I am doing? or am I being too silly. I am very new to htmldb please help
    George

    George - The most efficient SQL for your report would join all required tables and return the data you want to show. You could write a PL/SQL function to decode those foreign key IDs but that's kind of cheating (and slow).
    About no on answering your questions recently, I found that:
    Nov 3 - Carl gave a full response.
    Nov 5 - You asked a question of a person who last posted on that thread in October 2003.
    Nov 6 - You got a full response.
    Nov 7 - (server topic) You got a full response.
    Nov 7 - (wizards topic) Jes responded, you asked a follow-up, he hasn't gotten back to you but I don't really understand your question.
    Nov 7 - (fresh install topic) Your statements imply that there is no longer a problem.
    Nov 8 - (htmldb 2.0 Install help) No one responded. You should have bumped that.
    Nov 9 - You asked Holger a question in response to something he posted in February 2004.
    Nov 9 - (htmldb 2.0 with Oracle AS 10G) You got a full response from Joel.
    Nov 11 - Jes has not responded back yet. Bump it.
    Nov 14 - (Text not wrapping). No response, bump it.
    Nov 21 - (Yesterday) It hasn't been long enough to be concerned about no response, IMO.
    So there are a few posts that fell by the wayside, but I wouldn't say that you're being ignored. It might help if you provided more information in your initial postings so people don't have to ask you for more information. We do hope you'll stick around and keep asking questions when you need help.
    Scott

  • Report Attributes: Add column link and derived column

    On the Report Attributes page (4000:420), under the Tasks list on the right side of the page, there are 2 links, "Add column link" and "Add derived column". This is the first time I am noticing them.
    The usage is clear, they add columns to the report to function either as a drill-thru link column or just a read-only derived field.
    Doing it this way does NOT modify the source query for the report region.
    Is there any benefit to using this feature versus adding a "null column_link" or "null derived_col" columns to my source query then setting attributes for those columns?
    Thanks

    Well, one disadvantage I can see of using the 'Add Column link' is that if I have more than 1 of such columns, they all show up as '[column link]' on the Report Attributes page with no way to tell what the underlying links are. Instead, if I were to manually add these dummy columns to my query itself, I would give them meaningful column aliases that indicated where they link to.
    Suggestion: Maybe a tooltip could be added to the Report Attributes page for such columns which indicate what the underlying link is without actually going to the Edit page for that column.
    Thanks

  • Drill down in Table or Pivot for derived column

    Hi All,
    I have a requirement like Top 5 products should show the product names and remaining should go to *'Others'*. I achieved it by using Rank function and case when.
    ex: case when rank(product) <=5 then product else 'Others' end
    Now the problem is, I am not getting the Drill option for this column. When I use product column without case when or case when on same column like
    case when product = 'xyz' then 'abc' else product end. In this case drill is working.
    Can anybody suggest me to get the drill on the derived columns.
    Thanks in advance

    A similar thread was recently talked about here:
    In OBIEE charts, how do you make drill downs work on custom formulas?
    With a calculated column, you need to make sure the source query and destination query have the EXACT same formula and the same name for the field. If it is not 100% identical, it may not work correctly. (I typically use the NAVIGATE function to get to the second query rather than the Drill function.)
    Now in some cases, if you try to create a second drill down query with more details in it, the original formula doesn't work the way you want it to. The calculated formulas have to make sense in both source query and destination query in order to work properly. If you have a ranking of the Top 5 Products in the source query, the destination query also has to have the same ranking of Top 5 products in order to work. If you add more fields into the destination query (e.g., adding on product attributes, or # of records associated with that product name etc.), then sometimes the ranking / aggregation in the destination doesn't add up the same way. This causes the system to think that the formulas are different and prevents the drill down.
    I managed to get around this by having a 3rd query in between the original summary view and the detailed data view. So the sequence would be (for example):
    - Dashboard based summary query (including the calculated ranked product names formula)
    - drill down into virtually identical query (add on one slight bit of difference here, for example adding on a second Product Name field ... not a calculated version, but the actual name). Create a drill down this time by clicking on the regular Product Name field (don't drill down on the custom formula)
    - final detailed drill-down query
    You can format this intermediary drill down query to explain to users that they need to click a second time.
    It's not ideal, but it should work. Hope this helps.
    Ted

  • How to cast a column of a derived column in a view to NULL

    I have a derived column in my view and this column by default is picked up as not null.
    I want to cast it to null how can i do it ?
    Actual column
    column1 varchar(3) not null
    Expected column
    column1 varchar(3)  null
    Mudassar

    Shridar I  havent defined it but the derived column has been picked up as not null which is strange
    CREATE VIEW test
    AS
    SELECT 
    CASE
    WHEN COMPANY_SIZE IS NULL then  'a'
    ELSE 'b' 
    END AS
    column1 ----- added derived column identifier
    ,[Company_Size] AS [CompanySize]
    FROM xyz
    Mudassar

  • Can't change the connection string of SSIS package with derived columns?

    We upgraded SQL server 2008 to 2012, copied and converted all SSIS packages from Visual Studio 2008 to 2010.  When I opened a package in VS 2010 and tried to change the connection string, in the local connection managers, if the data source is another
    SSIS package B(.dtsx file) with derived columns, I can't change the connection string of package B. When I opened the file connection manager editor for package B and tried to locate a dtsx file in another location, saved the change, reopened the project.
    Package B still pointed to previous file.  Other packages without derived columns work fine. Any thoughts?

    We are using the package deployment model and refer to other packages in the same project. If
    we changed the path of package B (with derived columns) to "D:\Visual Studio 2010\xxxx", and refer it in package A, in the A's connection manager, the connection string of package B is still its previous location  "D:\Visual
    Studio 2008\xxxx". When we ran the package A in the SQL server agent, the data source is still
     "D:\Visual
    Studio 2008\xxxx", so how can I change it to "D:\Visual
    Studio 2010\xxxx"? Why has the package C (without derived columns) no such problem? thanks.

  • Checkbox derived column in report

    I added an HTML checkbox that has the same name for every row and a value of the pk for that row to a report. I also added a submit button.
    The submit button branches back to the same page.
    If I don't check ANY checkbox buttons the submit button just takes me back to the same report. If I even click one checkbox, I get a 404 "Page cannot be found" with the url saying: pls/htmldb/wwv_flow.accept
    why is this procedure doing this? How can I add a derived column containing a checkbox to a report for selection of report rows for further processing or adding of these rows to a "shopping cart/basket".

    Enough with this ..... link
    http://www.oracle.com/technology/products/database/htmldb/howtos/checkbox.html
    How many times do we have to see it in the forum....Enough.....
    Its so frustrating giving the same link time and time again...And the funny
    part is that most people's questions has nothing to do with that. But
    still some geniuses give the same link....I just feel so sorry for people
    who are struggling to get a answer and some idiots give the same link

  • Blank Column in Query

    Hi There
    Please advice me how to create a blank column in Query?
    Thanks in advance..
    Regards,
    Chandu.

    Hi
    I don't have any IO's regarding that.I just need create a column with some description then user can fill with data.
    How can i run that?
    Thanks in advance.
    Regards,
    Chandu.

  • Can we create prompts in Derived Table sql query

    Hi,
    I am trying to define derived table sql query as below. Though the syntax parsing is going through but when I am generating the report it is throwing and invalid prompt definition error.
    " select * from table_a where call_direction = @Prompt('Enter Call Direction','A','"derivedtable_a".SHORT_STRING',mono,free,not_persistent,) and
    where call_type = @Prompt('Enter Call Direction','A','"derivedtable_b".SHORT_STRING',mono,free,not_persistent,) "
    Can somebody please share your thoughts if this can be achieved in universe or not ?
    Appreciate immediate responses as it is a show stopper for my deliverable.
    Thanks in advance.
    Thanks and Regards,
    Shireen.

    Hi Shireen
    We can use prompt in the derived table. There is issue with the SQL that you have used while creating the Derived Table.
    Instead of using the "derivedtable_a".SHORT_STRING' field use the object from the class on which you are creating the derived table.
    For example: If you are creating a derived table in the sample universe efashion on Agg_yr_qt_rn_st_ln_ca_sr table then use the following query:
    SELECT *
    FROM Agg_yr_qt_rn_st_ln_ca_sr
    WHERE Agg_yr_qt_rn_st_ln_ca_sr.Yr = @Prompt ('Enter Value','C','Time Period\Year',mono,constrained)
    Hope this helps!
    Thanks

Maybe you are looking for

  • Printer can't be found on the network

    The printer has been working fine for months, and today it can't be accessed at its assigned IP address. No computer can print to it or find it, even when manually entering the IP address, although the printer is connected (it scans to a network fold

  • Shared thru iTunes: where is the file?

    I Created a doc (my resume) in Pages (2.5.2), "shared" it in PDF, via iTunes, but where is that file now? I need to upload it to the job site, but I don't know where to locate it on my iPad. Any ideas?

  • Change a numeric value to a date field

    If someone could please help I would appreciate to know how to change a numeric value to date value. Example: I ave a number 20080312 and I would likefor the field to read as follows in a date format, 03/12/08. i am not sure how to convert. Thanks Ji

  • Removal of t-code

    Hi All, We want to remove a t-code from a display role where the menu is not maintained. The S_TCODE is given as *. (Full authorization) how to go about the same. If we remove that from S_TCODE we need add all other entries which is very difficult. P

  • Subject line colour change

    Hi all, Today for the first time half my incoming mail has a subject heading colour of Gold & the other half the normal Black. Has anyone know why this should have happened & how I correct it please. Barney