Query sql

My requirment is
in my below query having 5 parameter if i pass all parameter values as null it show me all record from emp
if i pass few parameters value then it fetch only those record which i am passing in parameter
i did in this way ................i can get too many values as error
but can any one tell me using eigther decode or case function to get it..............(only sql query)
select case when empno is null then (select * from emp)
else (select * from emp where empno = empno)
end from (
select empno from emp
where empno in(&p1,&p2,&p3,&p4,&p5));

My requirment is
in my below query having 5 parameter if i pass all parameter values as null it show me all record from emp
if i pass few parameters value then it fetch only those record which i am passing in parameter
i did in this way ................i can get too many values as error
but can any one tell me using eigther decode or case function to get it..............(only sql query)
select case when empno is null then (select * from emp)
else (select * from emp where empno = empno)
end from (
select empno from emp
where empno in(&p1,&p2,&p3,&p4,&p5));
i want usage if nested decode or case function in sql query.

Similar Messages

  • How to set Query SQL Statement parameter dynamically in Sender JDBCAdpter

    Hi All,
    I have one scenario in which we are using JDBC Sender Adapter.
    Now in this case,we need to set Query SQL Statement with a SELECT statement based on some fields.
    This SQL statement is not constant, it would need to be changed.
    Means sometimes receiver will want to execute SQL statement with these fields and sometimes they will want to execute it with different fields.
    We can create separate channels for each SQL statement but again that is not an optimum solution.
    So ,I am looking out for a way to set these parameters dynamically or set SQL statement at Runtime.
    Can you all please help me to get this?

    Shweta ,
    <i>Sometimes receiver will want to execute SQL statement dynamically</i>....
    How you will get the query dynamically? Ok Let me assume, consider they are sending the query through file, then its definitely possible. But u need BPM and also not sender JDBC receiver adapter instead, receiver JDBC adapter.
    SQL Query File ->BPM>Synchronous send [Fetch data from DB]--->Response -
    >...............
    Do u think the above design will suit's ur case!!!!
    Best regards,
    raj.

  • Query SQL code gets deleted after export to Excel. "Query must have at least one destination field"

    Hi all,
    I'm getting really frustrated by this Access error. It happens when I export the result of a query through an Access macro to Excel, the first time it runs well but the next time, there is a chance that the query won't run and the error "Query
    must have at least one destination field" will be displayed. After that, I try to check the query SQL code and discover the code has vanished. I'm using simple Select query without joins, only "where", "group by" and "order by"
    statements.
    Thank you in advance for your help,
    Jesus 
    Edit:
    One of these queries are like the following (all of them are of this type):
    SELECT Field1, field2, field3, field4, field5, Sum(Field6) AS SumOfField6, Sum(Field7) AS SumOfField7
    FROM Table1
    WHERE Field6 is not null
    GROUP BY Field1, field2, field3, field4, field5
    Order By Sum(Field6) desc

    Hi Peter, 
    Thank you for your response, I updated the original question with one of the codes.
    Thanks,
    Jesus

  • Xi JDBC Adapter - Query SQL Statement & Update SQL Statement

    Hi!
    I configure the JDBC adapter sender (XI) to take data from Oracle database.
    I set the Query and Update SQL Statement in the Processing parameters of the communication channel in this way:
    Query SQL Statement :
    SELECT * FROM XI_TABLE WHERE STATUS = 'WAIT' ORDER BY ROW_NUM
    Update SQL Statement :
    UPDATE XI_TABLE SET STATUS = 'DONE', DATE = SYSDATE WHERE STATUS = 'WAIT'
    My question is :
    If a new record with the field STATUS = 'WAIT' is added to the table (xi_table) during the time between the execution of the query statement and the start of the update statement, what will happen to that record during the update?
    There is a way to avoid the update of that record? or to pass to the update statement only the record selected in the query statement?
    Please, may you give me some example?
    Thanks,
    Francesco

    hi,
    did you check "Isolation Level for Transaction"
    for the sender jdbc adapter?
    http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/content.htm
    Regards,
    michal

  • Export Query SQL multi-linee in XML format and Import XML in SAP

    Good morning
    Someone know if is possible after Export Query SQL on OITT and ITT1 with thousands rows in XML with values already change thru the query.
    Then import the XML without using loop in SAP with the above code vb.net
    oDistinta = DirectCast(m_oCompany.GetBusinessObjectFromXML(xmlFile, 0), SAPbobsCOM.ProductTrees)
                    Dim errCode As Integer = 0
                    Dim strErrore As String = ""
                    Dim iErrore As Integer = 0
                    oDistinta.Browser.ReadXml(xmlFile, 0)
                    errCode = oDistinta.Update
                    m_oCompany.GetLastError(iErrore, strErrore)
                    'on error
                    If iErrore <> 0 Then
    To make easy the program i post with 2 ProductTrees item. The 2 item already exist in OITT e ITT1.
    When i update the 1st item is modify but the 2nd not change.
    Here is the XML
    <?xml version="1.0" encoding="UTF-16"?>
    <BOM>
      <BO>
        <AdmInfo>
          <Object>66</Object>
          <Version>2</Version>
        </AdmInfo>
        <ProductTrees>
          <row>
            <TreeCode>V9998</TreeCode>
            <TreeType>iProductionTree</TreeType>
            <Quantity>1000.000000</Quantity>
            <U_SHI_MZDA>0</U_SHI_MZDA>
            <U_SHI_PUMA>0</U_SHI_PUMA>
            <U_SHI_PUUO>0</U_SHI_PUUO>
          </row>
        </ProductTrees>
        <ProductTrees_Lines>
          <row>
            <ItemCode>1047</ItemCode>
            <Quantity>5.000000</Quantity>
            <Warehouse>Mc</Warehouse>
            <Price>0.000000</Price>
            <Currency>
            </Currency>
            <IssueMethod>im_Backflush</IssueMethod>
            <Comment>
            </Comment>
            <ParentItem>V9998</ParentItem>
            <PriceList>2</PriceList>
            <DistributionRule>
            </DistributionRule>
            <U_IDE_POS>10</U_IDE_POS>
            <U_IDE_FASE>0</U_IDE_FASE>
            <U_IDE_OPER>10</U_IDE_OPER>
            <U_SHI_UndInv>N</U_SHI_UndInv>
            <U_SHI_Pri1>
            </U_SHI_Pri1>
            <U_SHI_Pri2>
            </U_SHI_Pri2>
            <U_SHI_Pri3>
            </U_SHI_Pri3>
            <U_SHI_Prgm>
            </U_SHI_Prgm>
            <U_SHI_Tim2>0.000000</U_SHI_Tim2>
            <U_SHI_Tim3>0.000000</U_SHI_Tim3>
            <U_SHI_DexNACQ>
            </U_SHI_DexNACQ>
            <U_SHI_BP>
            </U_SHI_BP>
            <U_SHI_PrcKit>0.000000</U_SHI_PrcKit>
            <U_SHI_ItmNACQ>
            </U_SHI_ItmNACQ>
            <U_SHI_LineOk>N</U_SHI_LineOk>
          </row>
        </ProductTrees_Lines>
        <ProductTrees>
          <row>
            <TreeCode>V9999</TreeCode>
            <TreeType>iProductionTree</TreeType>
            <Quantity>1000.000000</Quantity>
            <U_SHI_MZDA>0</U_SHI_MZDA>
            <U_SHI_PUMA>0</U_SHI_PUMA>
            <U_SHI_PUUO>0</U_SHI_PUUO>
          </row>
        </ProductTrees>
        <ProductTrees_Lines>
          <row>
            <ItemCode>1015</ItemCode>
            <Quantity>1000.000000</Quantity>
            <Warehouse>Mc</Warehouse>
            <Price>0.000000</Price>
            <Currency>
            </Currency>
            <IssueMethod>im_Backflush</IssueMethod>
            <Comment>
            </Comment>
            <ParentItem>V9999</ParentItem>
            <PriceList>5</PriceList>
            <DistributionRule>
            </DistributionRule>
            <U_IDE_POS>30</U_IDE_POS>
            <U_IDE_FASE>0</U_IDE_FASE>
            <U_IDE_OPER>30</U_IDE_OPER>
            <U_SHI_UndInv>N</U_SHI_UndInv>
            <U_SHI_Pri1>
            </U_SHI_Pri1>
            <U_SHI_Pri2>
            </U_SHI_Pri2>
            <U_SHI_Pri3>
            </U_SHI_Pri3>
            <U_SHI_Prgm>
            </U_SHI_Prgm>
            <U_SHI_Tim2>0.000000</U_SHI_Tim2>
            <U_SHI_Tim3>0.000000</U_SHI_Tim3>
            <U_SHI_DexNACQ>
            </U_SHI_DexNACQ>
            <U_SHI_BP>
            </U_SHI_BP>
            <U_SHI_PrcKit>0.000000</U_SHI_PrcKit>
            <U_SHI_ItmNACQ>
            </U_SHI_ItmNACQ>
            <U_SHI_LineOk>N</U_SHI_LineOk>
          </row>
        </ProductTrees_Lines>
      </BO>
    </BOM>
    Someone know the reason ?
    Thanks in advance.
    Regards

    Hi Gabriele,
    The issue is that the ReadXml method takes an index parameter which is the number of the object that you want to read from the XML data. In your code you are specifying index 0 which is the first product tree in your file so when you call the Update method this is the only record that will be updated. It is not possible to do a mass update using the DI API in this way, you must always load each object separately. You can use the GetXMLelementCount method of the Company object to find out how many product tree objects are in your file and then use the ReadXML method to load each one by incrementing the index parameter in a loop.
    Kind Regards,
    Owen

  • Can I use a OID rule for a Query SQL Lov of BIP?

    Hi. Can I use OID data (rules) for a query sql lov in BIP? Ex. filters users/store.
    Thank you.
    R.

    Hi,
    I didn't look at the example, but if you want to secure your application then you should use container managed security. Read this .
    Anyway, you could add this before return "good"; in your login_action()
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("username", user);Then, you can access this from anywhere in the application by using #{sessionScope.username}.
    Pedja

  • Query SQL database inside XSL

    Do you guys know how can I query SQL database select records and input them to XSL file?
    Let me know this is urgent.

    Is there an efficient way of doing this, rather than
    hardcoding all the less than,greater than lines?Sounds like you need to read this:
    http://java.sun.com/webservices/docs/1.1/tutorial/doc/index.html

  • Query SQL and output to text file then loop through list to execute

    It seems there's no obvious way to do what I want to below as everyone has their own take on querying SQL server with Powershell!
    I need to use PowerShell to connect to ServerA and query a test database and select Name from it.  The Name results of that query need to output to C:\names.txt and then I need a ForEach loop to go through that file line by line and execute some text
    against each Name from the list.
    Any ideas how I can achieve this?
    Thanks!

    I can't even output SQl to a table at the moment, the text file has a column header and about 50 empty rows in the file.
    $dataSource = "DEMO"
    $database = "TESTDB"
    $connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=True;"
    $query = "SELECT name FROM dbo.names"
    $connection = New-Object System.Data.SqlClient.SqlConnection
    $connection.ConnectionString = $connectionString
    $connection.Open()
    $command = $connection.CreateCommand()
    $command.CommandText  = $query
    $result = $command.ExecuteReader()
    $table = new-object "System.Data.DataTable"
    $table.Load($result)
    $format = @{Expression={$_.Id};Label="Name";width=25}
    $table | format-table $format | Out-File C:\export\servers.txt
    $connection.Close()

  • How to set query SQL on db throug item value?

    Hi
    I've two pages:
    the first page contain the item textfield value (P1_NAME) and second page contain the query SQL.
    Where the query sql instruction insert in the second page rendering?
    In the Items, in the buttons, in the computation, in the process?
    How display the results of query?
    Help Me!!!

    On re-reading I think I get it. When you open the second page, which could be anywhere, you'll have to tell me (could be a Branch, could be a linked column in a report, could be triggered from a button). Whervever the code that opens the second page is, you will see a setting labelled "Target is a" and the chosen selection will be "Page in this Appication" Right under that, you will see two other fields labelled "Set These Items" and "With These Values" this will let you set whatever items you wish on the page that you are opening.

  • Ask for a query SQL

    Hi,
    The schema's definition is:
    A
    =======================
    UserID
    SubTime
    ActiveTime
    DeactiveTime
    ExpireTime
    =======================
    I need to get records in the following format:
    2003-01-01,<userid>,<action type>
    The <action type> should be 1 or 2 or 3 or 4 which indicate the time is 'SubTime' or 'ActiveTime' or 'DeactiveTime' or 'ExpireTime'.
    For example, there is a record in database:
    UserID SubTime ActiveTime DeactiveTime ExpireTime
    1 2004-01-01 2004-01-02 2004-01-03 2004-01-04
    The search results should be:
    2004-01-01, 1, 1
    2004-01-02, 1, 2
    2004-01-03, 1, 3
    2004-01-04, 1, 4
    The search result should be order by time.
    The size of the table is very big, can anyone suggest a high performance query SQL? Thank you very much in advance!
    BR/Shirley

    Hi,
    select time,userid,action_type from
    (select UserID,SubTime,1 action_type from utab
    union all
    select UserID,ActiveTime ,2 from utab where where activeTime is not null
    union all
    select UserID,DeactiveTime ,3 from utab where where dectiveTime is not null
    union all
    select UserID,ExpireTime ,4 from utab where where ExpireTime is not null)
    order by 1
    Please chek with Perfermance.
    Bye
    Chitta

  • I want to query sql server database from oracle

    i want to query sql server database from oracle
    can anyone help me in this regard

    First of all - you are in the wrong forum.
    Look either for the Database general or search for Transparant / Heterogenous Gateways.
    cu
    Andreas

  • Query SQL with variables Parameters and user defined tables

    Hi  everyone
    I got a problem about Query SQL
    [dbo].[@CSOURCE]  is a user defined table
    select * from [dbo].[@CSOURCE]
    you can get the result in following
    code    name
    T01      newspaper
    T02      TV
    T03      radio
    T04      friends
    when I execute the following SQL   Statements ,I get an error
    SELECT T0.CardCode , 0.CardName ,T1.Name ,T2.SONumber
    FROM OCRD T0    LEFT JOIN [dbo].[@CSOURCE]  T1 ON T0.U_CSOURCE = T1.Code
                                 LEFT JOIN (SELECT  T0.CardCode ,COUNT(T0.DocNum)SONumber
                                 FROM ODLN T0  INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
                                WHERE T1.GroupCode =111
                                AND   (T0.DocDate >=[%0] or [%0]='')
                                AND   (T0.DocDate <=[%1] or [%1]='')   
                                GROUP BY T0.CardCode) T2 ON T0.CardCode=T2.CardCode
    WHERE T0.GroupCode =111
    and  T0.CardType ='C
    Is there anyone can correct it for me
    thank you very much
    Edited by: Li Mishan on Jul 17, 2008 9:36 AM
    Edited by: Li Mishan on Jul 17, 2008 9:40 AM

    I am sorry .It is just a mistake of my typewriting.
    The following is the whole SQL
    dbo.@CSOURCE is a user table.It's content is
    code  name
    T01    newspaper
    T02    TV
    T03    radio
    T04    friends
    declare @m int
    declare @FromDate DateTime
    declare @ToDate DateTime
    set @m=(SELECT count(*)  FROM ORDR T0 WHERE T0.DocDate >=[%0] and  T0.DocDate <=[%1])
    set  @FromDate=[%0]
    set  @ToDate=[%1]
    /*****************If I do not connect user tavble dbo.@CSOURCE ,I will succed *****************************************************/
    SELECT T0.CardCode ,T0.CardName ,T2.SONumber,T1.Name
    FROM OCRD T0  LEFT JOIN [dbo].[@CSOURCE] T1 ON T0.U_CSOURCE = T1.Code
                               LEFT JOIN (
                                                SELECT T0.CardCode ,COUNT(T0.DocNum)SONumber                                            FROM ODLN T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
                                                WHERE T1.GroupCode =111
                                                AND (T0.DocDate >=@FromDate or @FromDate='')
                                                AND (T0.DocDate <=@ToDate  or  @ToDate ='')                                                                               
    GROUP BY T0.CardCode
                                            ) T2 ON T0.CardCode=T2.CardCode
    WHERE T0.GroupCode =111
    and T0.CardType ='C'
    when I excute the SQL, It return a error , whith says the column name '%0'  is invalid.
    If I delete "set @m=(SELECT count(*)  FROM ORDR T0 WHERE T0.DocDate >=[%0] and  T0.DocDate <=[%1])"
    and rewrite "set  @FromDate='2008.05.01' set  @ToDate='2008.07.01' "
    It Shows the following results
       CardCode     CardName     SONumber     name
    1      000070        Deng. Jiahua   1                newspaper
    2      000293        LU .Weijuan    1                radio
    3      000313         Xie .Jifang       3               TV
    Edited by: Li Mishan on Jul 18, 2008 4:42 AM
    Edited by: Li Mishan on Jul 18, 2008 4:43 AM
    Edited by: Li Mishan on Jul 18, 2008 5:43 AM

  • Query SQL Statement & Update SQL Statement

    Hi!
    I configure the JDBC adapter sender (XI) to take data from MSSQL database.
    I have to run select like this:
    SELECT
    tblMilestone.Site,
    tblMilestone.Revision,
    tblMilestone.MilestoneNameID,
    tblMilestone.ApprovedDate,
    tblMilestoneName.MilestoneName
    FROM
    tblMilestoneName
    INNER JOIN tblMilestone ON tblMilestoneName.MilestoneNameID = tblMilestone.MilestoneNameID
    WHERE tblMilestone.StatusCode = 1;
    My question is what "Update SQL Statement" I should use in communication channel definition? I only need to update tblMilestone or this two tables?
    Maybe you give me some example.

    Check this from SAP help...
    Update SQL Statement
    You have the following options:
    &#9679;     Enter a valid SQL statement that is to be applied to the database once the data (determined from the Query SQL Statement) has been successfully sent to the Integration Server/PCK.
    It must be an INSERT, UPDATE, or DELETE statement.
    &#9679;     In place of the SQL statement, you can also enter <TEST>. Once the data determined from Query SQL Statement has been successfully sent, the data in the database remains unaltered.
    This is recommended if the data has not only been read, but also changed by a stored procedure entered under Query SQL Statement.

  • MS Access querying SQL Server: How to configure Network ACL?

    I need to set up a highly restrictive ACL for access to a particular SQL server in our network.  This ACL will reside on our core switch at the "front door" of our network and permit access to the SQL server only using the ports that
    are necessary.  The purpose is to A) Try to keep unauthorized users from gaining access to the host server and B) Should someone somehow gain unauthorized access to the host server. keep them from being able to "hop off" to other PC's on
    the network. 
    The server will be accessed by clients using MS Access to query the SQL database and bring back reports.  A few admins are actually able to make minor changes to the database such as updating a user list or location list. In other words, both
    read and write access is needed to the SQL database.
    I know that the default SQL server port is 1433, but according to a Microsoft Support article I read, "client ports are assigned a random value between 1024 and 5000".
    I was really hoping I could just put something like "permit PC1 access to SQL Server on Port 1433" in my ACL, but after reading the MS Support article it sounds like I've got to allow almost 4,000 ports through?
    Could someone help demystify this for me so I can build the right ACL?

    The tool to use is SQL Server Configuration Management.
    But what you can configure is which port SQL Server listens to. Which port the client listens to is not controllable as far as I know. But that can of course be many, since a client can have many connections to SQL Server. (And the range is not
    restricted to 1024-5000. I connected over TCP locally, and I see this with netstat -a
      TCP    127.0.0.1:6621         NATSUMORI:ms-sql-s     ESTABLISHED
    Then again, I don't see why you would have to open any ports for the clients at all. I have never heard of this being a problem.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Insert query + sql

    Hello everyone
    Can anyone could tell me what is the error in the following syntax of insert command in sql.
    String sql ="insert into ProvidentFundCalculator(Month,Basic,Epf,Epf_Difference,PFund,M_PFund,Provident_Id,Emp_Id) values ('"January"',basic,epf,epfDifference,pFund,mFund,"1",empId)";
    in this query , i have hardcoded "january" and "1" while other variables are the calculated ones .
    error on jboss server is :
    The name basic is not permitted in this context.Only constants,variables or expressions are aloowed here.Column names are not permitted.

    String sql ="insert into ProvidentFundCalculator(Month,Basic,Epf,Epf_Difference,PFund,M_PFund,Provident_Id,Emp_Id) values ('"January"',basic,epf,epfDifference,pFund,mFund,"1",empId)";
    This is not the correct way to form a String. You need to revisit the basics again. You are adding double quotes in between without proper escaping. Also, you are putting variable names within the String, which will not be a proper SQL query.
    The sql string should look like
    String sql = "insert into ProvidentFundCalculator (Month, Basic, Epf, Epf_Difference, "
                   +"PFund, M_PFund, Provident_Id, Emp_Id) values ("
                   +" 'January', " +basic +", " +epf +", " +epfDifference +", "
                   +pFund +", " +mFund +", " +"'1'" +empId +" )";The better way of doing it is to use a PreparedStatement and use the appropriate setXxx() methods for the parameters.

Maybe you are looking for

  • ICloud Control Panel - Outlook 2007

    My Outlook 2007 crashes constantly after Update to iCloud Control Panel 3.0 for Windows (Windows 7)! What can i do?

  • No output at all from stored procedure?

    if I compile and run stored procedure as follows: 1. right click on stored proceudre, select "run" 2. update input parameter with values 3. select 'OK' I get the following in the running-log, but no result. If I run the in a SQL tab, the data will sh

  • When will lost status be restored?

    When Apple changed the boards I was forced to reregister and lost my original joining date, information, and all the points and such that I had accumulated. Now that it seems important to have the point system back, I want all my old points and the l

  • How automaticaly create user's mailboxes with content for test purposes?

    Hi all! Tell me please, how can i imitate outlook's users activity. In result i need 10...200 mailboxes with 100-200 elements (mail, calendar's events, meeting requests and etc) and up to 100Mb size of each mailbox. It's need for creating test enviro

  • Can't send mail frim iPad

    My iPad was working perfectly well until suddenly It stopped being able to send mail. Kept getting message saying that I had not entered my password. Double-checked everything,tried setting up the account manually,restoring the iPad software ( it wor