Query on using Variables in Oracle Query

Hi
i am new to Oracle, i have tried extracting data from the Oracle Database using the following Query which includes 1 variable SYSDATE_UTS, however when i try to execute the Query i get an error. Please let me know what am i doing wrong and how can i correct it.
Error Message
ORA-06550: line 4, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
Oracle Query
DECLARE SYSDATE_UTS NUMBER := (sysdate-to_date('19700101','yyyymmdd'))*86400;
BEGIN
SELECT
INCIDENT_NUMBER,
to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME,
,GROUP_TRANSFERS
,LAST_MODIFIED_BY
,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
,CASE
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
ELSE 'UNKNOWN'
END AS AGE_GROUP
FROM IncidentDataBase
and STATUS not in (4,5,6)
and rownum <10;
END;

Hi Frank
i am using the following Oracle Version
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE     10.2.0.5.0     Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
and Quest Toad for Oracle to write and execute the queries:
Toad for Oracle Xpert
Version 10.1.1.8
The code i am using is:
variable SYSDATE_UTS NUMBER;
exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
SELECT
INCIDENT_NUMBER,
to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME
,GROUP_TRANSFERS
,LAST_MODIFIED_BY
,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
,CASE
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
ELSE 'UNKNOWN'
END AS AGE_GROUP
FROM IncidentDataBase
WHERE STATUS not in (4,5,6)
and rownum <10;
Notes:
1. When i put the cursor before "variable" (starting of the query) and execute the script i get an Error: ORA-00900: invalid SQL statement.
2. When i put the cursor just before "SELECT" i get a pop up.
a. it is a Toad window which displays the available variables (in this case :SYSDATE_UTS).
b. gives me a dropdown option to select the type (by default VARCHAR2 is selected).
c. there is a value field where i need to enter the value for the Variable.
d. the SQL statement shown in this dilog box does not include the 1st 2 lines
variable SYSDATE_UTS NUMBER;
exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
Q: is there something wrong in the syntax i am using?
Sven W. - I have been using your method all these days, which works just fine. i wanted to know how i could use a variable instead.
Business Requirement - My whole intent is to calculate the Age of an incident (Difference between "Reported Date" and current date) and to assign Age Groups (0-1 Days, 2-4 Days,....,20+ Days).
Edited by: 921713 on Mar 19, 2012 12:23 PM

Similar Messages

  • Using variables in a query

    Hello all,
    I just tried to use variable in a query and dont know how to
    output the content in the query. As you can see from what i am
    trying, i would only get the name of the query and the field name
    not the output. Please tell me the idiotic thing that i am over
    looking.
    Matt

    Mike,
    Thanks, ...if you were to output the url.fieldused, then you
    would get the name of the field, not the value of the field. The
    getfield[ ] is not something that i am familier with and cant seem
    to find documentation on this...I need to output the value of the
    field and this is where i am stuck.
    Matt

  • How to find out query name using Elements of the query builder.

    Hi SDNers,
    how to find out query name using Elements of the query .
    thanks,
    satyaa

    Hi,
    For having a look at the relation between BEx tables,check the link below:
    http://wiki.sdn.sap.com/wiki/display/BI/ExploretherelationbetweenBEx+Tables
    -Vikram

  • Using variables in Oracle

    Hi,
    I am using java and oracle and I want to know the way to achieve the "user-defined variables" functionality of mysql
    [http://dev.mysql.com/doc/refman/4.1/en/user-variables.html]
    Basically I want my update query/PL-SQL block to first define a variable and then refer it multiple times in the query.I also want to return the number of updated rows to my application code in java
    I saw DEFINE variable,bind variables etc,but dont know what exactly should I use
    Thanks in advance
    Ananth

    I am looking to use the variables in the query
    itself.
    Ex: select @t1:=100,@t2:=@t1+10 from tbl_name where
    col_name > @t1 and col_name < @t2
    [This is a simple ex.I want to use current timestamp
    instead of 100 as first variable's value]
    Also,as I have mentioned,I need to use these in
    update statements also and return the no. of updated
    rows to java codeUse Declare on the beginning of a PL/SQL block to declare variable names and types. Then just use them in the code (including update statements) without any prefix (@ is not needed in oracle). As a clear difference from MySQL, you don't need to use select to set a variable value if it does not depend on a query, just use the := operator. To read values from a query into variables, use "select ... into" syntax.
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm#LNPLS01345
    gojko adzic
    http://gojko.net

  • How to find Query name using Variable name (by Customer exit code in CMOD).

    Dear SDN,
    Enhancement name RSR00001.....Function Module name.....EXIT_SAPLRRSO_001...Include ZXRSRU01...
    Some x variable coding in done here.
    How can I find out the Query name for the X variable?
    Wating for reply...
    Thanks & Regards,
    Praveen.K

    Dear,
    I have got answer..
    Method 1 :Right click on variable in Query Designer and find the where used list.
    Method 2 : SE16--> RSZGLOBV -->Enter the variable VNAM as 'Variable Name' ->Get the VARUNIID> Go to table RSZELTXREF --> Enter the values of VARUNIID in TELTUID --> Get the list of SELTUID --> Go to table RSZCOMPDIR --> Enter the values of SELTUID in COMPUID --> Get the list of COMPID -->COMPID is the list of queries
    Thanks & Regards,
    Praveen.K

  • Using variables in the Query Designer

    Hi,
    I have 2 variables 'Z_COMP_CODE' and 'Z_BUS_AREA'. The type of 'Z_COMP_CODE' is single value ,customer exit and ready for input . The type of  'Z_BUS_AREA' is selection option,customer exit and not ready for input. I want the 2 variables to work like this: when 'Z_COMP_CODE' has the value '3000', 'Z_BUS_AREA' should have all the values excluding '2106'. Now in CMOD I have written the following codes for 'Z_BUS_AREA', But it does not work. 'Z_BUS_AREA' get no value while the query is running.Can somebody tell me how to correct it?thx.
    WHEN 'Z_BUS_AREA'.
    IF i_step = 2.
             READ TABLE i_t_var_range INTO l_s_range_v
                WITH KEY vnam = 'Z_COMP_CODE'.
             IF sy-subrc EQ 0.
               IF l_s_range_v-low = '3000'.
                 l_s_range-low = '2106'.
                 l_s_range-sign = 'E'.
                 l_s_range-opt = 'EQ'.
                 INSERT l_s_range INTO TABLE e_t_range.
               ENDIF.
             ENDIF.
           ENDIF.

    It should be Customer Exit only.
    Your code looks like ok to me. Have you tried to debug it? is l_s_range taking values?
    Also i don't know much abt insert statement...may be same as append...but just try with append statement also.
    Message was edited by:
            KJ (Kamaljeet)

  • How to know whether query is using Indexes in oracle?

    Please let me know necessary steps to check whether query using indexes.

    Try the below and check the explain plan.. See below explain plan using index marked as "RED" font
    SET AUTOTRACE TRACEONLY EXPLAIN
    SELECT * FROM emp WHERE empno = 7839;
    Execution Plan
    Plan hash value: 2949544139
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |        |     1 |    38 |     1   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    38 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX UNIQUE SCAN         | PK_EMP |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("EMPNO"=7839)

  • Query with bind variable, how can use it in managed bean ?

    Hi
    I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
    Thanks

    Put the query in a VO and execute it the usual way.
    If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page.

  • How to execute a select query stored in variable

    Hello  helpers ,
    I have some "select queries" stored in the database . Now I can derive this query in some variable . How do I execute this query from the variable .
    example :
    Data Query type char50 .
    QueryVar = 'Select MATNR from MBEW where BWKEY = '0001' . '
    How do I execute this Query stoored in variable QueryVar in ABAP program ?
    Thanks a lot for helping .
    Regards
    Shashank

    Shashank,
    It is also possible to use (column_syntax) and (dbtab_syntax) together with (cond_syntax) when using SELECT statements in ABAP. For more info on (column_syntax) and (dbtab_syntax) just have a quick look at ABAP Keyword documention on SELECT statement (hit F1 on SELECT then scroll down to Select->Select result->Select Columns....)
    So in your case, you need to separate out (split) the value in 'wa_itab-query' into other variables or append into separate internal tables using common keys etc. - then looping at those tables with the common key (READ TABLE WITH KEY....) use the following syntax at the time of triggering the SELECT query:
    SELECT (column_syntax)
           FROM (dbtab_syntax)
           WHERE (cond_syntax).
    Also worth a look at this example below:
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
                p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
             fldate TYPE sflight-fldate,
             carrname TYPE scarr-carrname,
             connid   TYPE spfli-connid,
           END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
                   WITH UNIQUE KEY fldate carrname connid.
    DATA: column_syntax TYPE string,
          dbtab_syntax TYPE string.
    column_syntax = `c~carrname p~connid f~fldate`.
    dbtab_syntax = `( ( scarr AS c `
      & ` INNER JOIN spfli AS p ON p~carrid  = c~carrid`
      & ` AND p~cityfrom = p_cityfr`
      & ` AND p~cityto   = p_cityto )`
      & ` INNER JOIN sflight AS f ON f~carrid = p~carrid `
      & ` AND f~connid = p~connid )`.
    SELECT (column_syntax)
           FROM (dbtab_syntax)
           INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT itab INTO wa.
      WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Hope this helps.
    Cheers,
    Sougata.

  • Some diffrence in oracle query and mysql query

    sir i see both query in SessionBean1
    mysql query
    SELECT ALL usert.username,
    usert.userid,
    usert.camid FROM usert
    this not use user name
    oracle query
    SELECT ALL MFA.LUSER.USERID,
    MFA.LUSER.TITLE,
    MFA.LUSER.CAMPID,
    MFA.LUSER.PWD,
    MFA.LUSER.USERNAME
    FROM MFA.LUSER
    the user name mfa is use in this query you can see
    this is main diffrence
    but i yse both in code but not get result
    try {
    RowKey userRowKey = luserDataProvider.findFirst
    (new String[] { "MFA.LUSER.USERNAME" },
    new Object[] { textField4.getText()});
    if (userRowKey == null) {
    textField3.setText("11111");
    return null;
    } else {
    textField3.setText("22222");
    return null;
    catch (Exception e) {
    log("Cannot perform login for userid " + textField3.getText(), e);
    error("Cannot perform login for userid " + textField3.getText() + ": " + e);
    textField3.setText("77777");
    return null;
    problem in only oracle not in mysql
    please give me idea how i get result
    thank you

    can you post your query with explain plan for both 9i version and 10g version.
    Thanks,
    karthick.

  • Using procedure with multiple out variables in a query

    Hi,
    We have a procedure that is time-consuming, which returns 4 variables as out parameters:
    procedure calc_values(id in number, val1 out number, val2 out number, val3 out number, val4 out number) isThe id uniquely identifies an product in our database.
    I would like to use this in a query (or view), in the form
    select s.id, val1, val2, val3, val4 from something s, product_table p
    where s.id = p.idI have tried the following approach, but I am kinda stuck
    * define a type
    * define a table of this type
    * write a wrapper function that calls this procedure and returns the results as a table
    * pivot the table into columns
    * join this with the product table
    It feels like I am on the wrong track, i am having trouble to get the id from the product table back into the wrapper function.
    Is there a better approach to this? I am on oracle 10g
    Thanks!
    Rob

    Te below is my interpretation of what you asked to do. I don't really know that it is what you want to do or what you should do.
    CREATE TYPE prod_vals_def
    AS OBJECT
    (VAL1      NUMBER,
      VAL2      NUMBER,
      VAL3      NUMBER,
      VAL4      NUMBER
    create or replace
    TYPE   prod_vals_tab
    AS TABLE OF prod_vals_def;
    CREATE FUNCTION pvals (p_prod_id  NUMBER)
    RETURN prod_vals_tab PIPELINED
    AS
      TYPE         ref0 IS REF CURSOR;
      cur0         ref0;
      out_rec      prod_vals_def
                := prod_vals_def(NULL,NULL,NULL,NULL);
    BEGIN
      -- CASE replacing SELECT against table I'm not going to create
      CASE p_prod_id
        WHEN 1 THEN
          out_rec.val1 := 1;
          out_rec.val2 := 2;
          out_rec.val3 := 3;
          out_rec.val4 := 4;
        WHEN 2 THEN
          out_rec.val1 := 2;
          out_rec.val2 := 3;
          out_rec.val3 := 4;
          out_rec.val4 := 5;
        WHEN 3 THEN
          out_rec.val1 := 3;
          out_rec.val2 := 4;
          out_rec.val3 := 5;
          out_rec.val4 := 6;
        WHEN 4 THEN
          out_rec.val1 := 4;
          out_rec.val2 := 5;
          out_rec.val3 := 6;
          out_rec.val4 := 7;
        ELSE
          out_rec.val1 := 0;
          out_rec.val2 := 0;
          out_rec.val3 := 0;
          out_rec.val4 := 0;
      END CASE;
      PIPE ROW(out_rec);
    END pvals;
    WITH s_tab AS
      (SELECT 1 AS prod_id FROM dual
       UNION ALL
       SELECT 2 AS prod_id FROM dual
       UNION ALL
       SELECT 3 AS prod_id FROM dual
       UNION ALL
       SELECT 4 AS prod_id FROM dual
    SELECT s.prod_id, p.val1, p.val2, p.val3, p.val4
    FROM   s_tab s,
           TABLE(pvals(s.prod_id)) p
    PROD_ID  VAL1     VAL2     VAL3     VAL4    
    1        1        2        3        4       
    2        2        3        4        5       
    3        3        4        5        6       
    4        4        5        6        7    

  • Query Stripping not working properly when using variable in the report

    We have issue with WEBI document that have query stripping enable.
    Once the query stripping enabled there is no data return in the report.
    We have investigate on the problem, the query stripping function are notable to retrieve objects that indirectly used in the report
    as we have
    many variable in the reports.
    Ex.
    Var1 = object1 + object2
    Var2 = Object3 + Object4
    Var3 = Var1 + Var2
    Var4 = Object1 + Object2 + Object3 + Object4
    If we use only Var3 in the report, the object1,2,3,and 4 will not be
    retrieve.
    But if we are using Var4 in the report, the object1,2,3,and 4 will be
    retrieve properly.
    Please let me know is it a by-design behavior, if yes please share points on it

    Hi Amit,
    Thank you for response, however i already had alook on that VIdeo and it tells us about the basic enabling of query stripping.
    But my question is when we have a Variable in a report which is dependent on the other two variables it gives me #error so is it by design or not.
    Regards,
    Abhinav

  • Using a characteristic value from an infoCube as a variable in a query

    Hi gurus!
    I have a query based on an infoCube where I make a restricted key figure. I restrict the key figure by selecting a specific month using 0calmonth.
    I need to create a variable that represents a specific month which will change every year. I have this month value stored in another infoCube. In this infoCube I have 0employee and for each employee the characteristic 0calmonth represents the month I need to use in my other query.
    So my question is: how can I retrieve the the value from 0calmonth (fx. 012009) from one infoCube and use it as an input in my other query for restricting the key figure using 0calmonth?
    Thank you!
    Best regards,
    Morten

    Hi guys,
    Thanks for your help so far. I would like to use the replacement path using another query. It seems more simple since I don't need to do any ABAP programming.
    However, it doesn't work for me. I made a pre-query on the infoCube, which contains the month I need for my other query. This pre-query uses a variable which restricts the data output to only data for current year up to current month. So if my input is 072009, then I will receive data for 012009-072009. My query result will then show me the month I need, since there will only be data for one specific month. So for 2009, the month that contains any data will be 052009. I need this month(052009) in my other query.
    So, in my original query I made a new variable for 0calmonth and I chose replacement path and the pre-query. I made a restricted key figure where I use the replacement path query. However, I am gettings errors, when I check the report and no data is available when I execute the query. The error says:
    Variable "prequery_variable" cannot be used in selection "key figure 1"; remove
    How you seen this error before?
    Thank you!

  • How to get a field that using variable in order to create a query

    Hi,
    I found a difficulty when creating a query. so, I would like to ask you some question.
    1. How to get a field that using variable which that field I want to put it in my query?
    For example, I would like to take quantity field in inventory audit report. And when I put my cursor in
    quantity field, there was only variable, item, etc. How to get this and put it in query?
    2. How to combined the invoice quantity with inventory audit report quantity?
    3. I have a query like this:
    SELECT distinct T0.[DocDate] as 'Tanggal', T0.[DocNum] as 'No.Faktur', T1.[ItemCode] as 'Kode Barang',
    T1.[Dscription] as 'Deskripsi', T1.[Quantity] as 'Quantity', ((T1.[LineTotal])/(T1.[Quantity])) as 'Harga
    Satuan', T1.[LineTotal] as 'Harga Total', T3.[CalcPrice] as 'HPP Satuan', ((T3.[CalcPrice]) * (T1.
    [Quantity])) as 'HPP Total', T4.[ItmsGrpNam] as 'Jenis Barang', T5.[SlpName] as 'Nama Sales', T1.
    [WhsCode] as 'Kode Gudang' FROM [dbo].[OINV] T0 INNER JOIN [dbo].[INV1] T1 ON T0.DocEntry =
    T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OINM T3 ON T2.ItemCode
    = T3.ItemCode INNER JOIN OITB T4 ON T2.ItmsGrpCod = T4.ItmsGrpCod INNER JOIN OSLP T5 ON
    T0.SlpCode = T5.SlpCode WHERE T3.[TransType] = '13' and T3.[CreatedBy] = T1.[DocEntry] and T0.
    [DocDate] >=[%0] and T0.[DocDate] <=[%1] and T4.[ItmsGrpNam] =[%2] and T1.[WhsCode] =[%3]
    Is it possible if I just take one invoice with invoice quantity and only show up at once although I have a
    lot item cost for that item? (because I'm using FIFOmethod).
    Please help me.. cause I'm stuck with this thing :l.
    Thank you very much, and I'm waiting your respon soon.
    Regards,
    Sisca

    Try this one:
    SELECT distinct T0.DocDate as 'Tanggal', T0.DocNum as 'No.Faktur', T1.ItemCode as 'Kode Barang',
    T1.Dscription as 'Deskripsi', T1.Quantity as 'Quantity', ((T1.LineTotal)/(T1.Quantity)) as 'Harga
    Satuan', T1.LineTotal as 'Harga Total', T3.CalcPrice as 'HPP Satuan', ((T3.CalcPrice) * (T1.
    Quantity)) as 'HPP Total', T4.ItmsGrpNam as 'Jenis Barang', T5.SlpName as 'Nama Sales', T1.
    WhsCode as 'Kode Gudang'
    FROM dbo.OINV T0 INNER JOIN dbo.INV1 T1 ON T0.DocEntry =T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OINM T3 ON T2.ItemCode = T3.ItemCode AND T3.TransType = '13' and T3.CreatedBy = T1.DocEntry AND T3.Warehouse = T1.WhsCode
    INNER JOIN OITB T4 ON T2.ItmsGrpCod = T4.ItmsGrpCod
    INNER JOIN OSLP T5 ON T0.SlpCode = T5.SlpCode
    WHERE T0.DocDate >=[%0\] and T0.DocDate <=[%1\] and T4.ItmsGrpNam =[%2\] and T1.WhsCode =[%3\]
    Thanks,
    Gordon

  • Query rule using query variables

    Hi All,
    I am working on a query rule in SharePoint 2013. I am trying to build a query text using query variables to provide profile based results to the users. The query text which I am using in the query builder is of the following format:
    {SearchBoxQuery} CombinedLanguage:{User.PreferredContentLanguage}
    but its not taking the user.preferredcontentlanguage value. Has any one worked on similar type of query rules using query variables? Please share your suggestions.
    Thanks !!

    Hi,
    As I understand, you cannot get the user.preferredcontentlanguage value.
    1. Make sure you have set the value of query variable {user.preferredcontentlanguage}, it will return -1 if not set.
    2. Make sure you search in the right result source.
    3. Please check the crawled property mapped to the managed property CombinedLanguage and make sure that there is at least one value indexed by the crawled property equal to the {user.preferredcontentlanguage}.
    The article below is about the query variables.
    https://technet.microsoft.com/en-us/library/jj683123.aspx
    The article below is about the different query variables return different result examples.
    http://techmikael.blogspot.in/2014/05/s15e03-query-variables-constant-trouble.html
    Best regards
    Sara Fan
    TechNet Community Support

Maybe you are looking for