SQL query returns few rows, but holds on with several Gbs of RAM memory used

If I perform the following query:
SELECT d.DocumentGUID, d.DocumentID
FROM ImportDataBase.dbo.Document d
LEFT OUTER JOIN ContentDataBase.dbo.Document d2 ON (d.DocumentGUID = d2.DocumentGUID)
WHERE ( d2.DocumentGUID IS NULL ) -- new document in the ImportDB
OR ( d2.DocumentGUID IS NOT NULL AND d.QueryContent <> d2.QueryContent ) -- modified document in the ImportDB
It returns around 1000 rows and takes about 3 minutes to complete
It also raises up the RAM memory used from 2GB to 9GBs. 
This memory used will remain used untill I restart the server. I have no need to make use of that memory, I already copied the returned rows of that query into a note pad for example. And any other reason of SQL has to  to keep that memory stored by
that query, I  dont want it.
Is there a way to release that memory I really dont need my SQL server to keep, without having to restart the SQL server?
and without topping the max memory the sql server uses, since I need my SQL server to use as much as it needs in other tasks(I dont think it needs to hold on to the above query memory used)
Thank You very much.

Is there a way to release that memory I really dont need my SQL server to keep, without having to restart the SQL server?
and without topping the max memory the sql server uses, since I need my SQL server to use as much
A query can be resource intensive even if it returns a single row. Generally it is a good idea to set SQL Server MAX memory.
BOL: "Optimizing Server Performance Using Memory Configuration Options
The memory manager component of Microsoft SQL Server eliminates the need for manual management of the memory available to SQL Server. When SQL Server starts, it dynamically determines how much memory to allocate based on how much memory the operating system
and other applications are currently using. As the load on the computer and SQL Server changes, so does the memory allocated. For more information, see Memory Architecture.
The following server configuration options can be used to configure memory usage and affect server performance:
•min server memory
•max server memory
•max worker threads
•index create memory
•min memory per query
The min server memory server configuration option can be used to ensure that SQL Server does not release memory below the configured minimum server memory once that threshold is reached. This configuration option can be set to a specific value based on the
size and activity of your SQL Server. If you choose to set this value, set it to some reasonable value to ensure that the operating system does not request too much memory from SQL Server, which can affect SQL Server performance.
The max server memory server configuration option can be used to specify the maximum amount of memory SQL Server can allocate when it starts and while it runs. This configuration option can be set to a specific value if you know there are multiple applications
running at the same time as SQL Server and you want to guarantee that these applications have sufficient memory to run. If these other applications, such as Web or e-mail servers, request memory only as needed, then do not set the max server memory server
configuration option, because SQL Server releases memory to them as needed. However, applications often use whatever memory is available when they start and do not request more if needed. If an application that behaves in this manner runs on the same computer
at the same time as SQL Server, set the max server memory server configuration option to a value that guarantees that the memory required by the application is not allocated by SQL Server."
LINK: 
http://technet.microsoft.com/en-us/library/ms177455(v=sql.105).aspx
Memory configuration:
http://www.sqlusa.com/bestpractices/memory-configuration/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

Similar Messages

  • SQL Query returning no rows, please help!!

    I have a table that contains user audits for a particular procedures alongwith the date stamp. Now, I want to list all the procedures not accessed by the users within the last 6 months. Or, all the procedures that have not been used/accessed during the last 6 months.
    This is what I am trying but is not returning any rows:
    SELECT DISTINCT proc_name,
    TRUNC (entry_date)
    FROM log_web
    WHERE proc_name NOT IN (SELECT proc_name
    FROM log_web
    WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180))
    ORDER BY 2 DESC
    Please advise.
    Thank you in advance.

    Two possibilities leap to mind.
    First, are you sure that there are any prodcedures not accessed in the last six months?
    Second, is there a chance that there could be records with a null value in proc_name? If the sub-query used in a NOT IN predicate returns even one null value, the query will return no rows.
    Does this return rows?
    SELECT DISTINCT proc_name, TRUNC(entry_date)
    FROM log_web
    WHERE proc_name NOT IN (SELECT proc_name
                            FROM log_web
                            WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180) and
                                  proc_name IS NOT NULL)
    ORDER BY 2 DESCJohn

  • Sql Query Returns repeating rows

    Oracle Version : 10g R2.
    DDL & DML
    CREATE TABLE T1
       (     CCODE VARCHAR2(4 BYTE),
         PNUM VARCHAR2(16 BYTE),
         CTYPCDE VARCHAR2(4 BYTE)
    INSERT INTO T1 VALUES ('0001','003526892','0007');
    INSERT INTO T1 VALUES ('0001','06767019','0006');
    INSERT INTO T1 VALUES ('0001','14787-10-900','0007');
    INSERT INTO T1 VALUES ('0002','003445803','0009');
    INSERT INTO T1 VALUES ('0002','000000','0018');
    INSERT INTO T1 VALUES ('0002','001645156','0008');
    INSERT INTO T1 VALUES ('0002','001646283','0008');
    INSERT INTO T1 VALUES ('0025','002587509','0008');
    INSERT INTO T1 VALUES ('0025','02507462', '0008');
    INSERT INTO T1 VALUES ('0025','02565229', '0008');
    INSERT INTO T1 VALUES ('0025','000943965','0007');
    CREATE TABLE XWLK
       (     CTYPCDE VARCHAR2(4 BYTE),
         CODE VARCHAR2(85 BYTE)
    INSERT INTO XWLK  VALUES ( '0004','70');
    INSERT INTO XWLK  VALUES ( '0005','05');
    INSERT INTO XWLK  VALUES ( '0006','05');
    INSERT INTO XWLK  VALUES ( '0007','05');
    INSERT INTO XWLK  VALUES ( '0007','10');
    INSERT INTO XWLK  VALUES ( '0008','15');
    INSERT INTO XWLK  VALUES ( '0008','20');
    INSERT INTO XWLK  VALUES ( '0009','25');
    INSERT INTO XWLK  VALUES ( '0010','75');
    INSERT INTO XWLK  VALUES ( '0010','80');
    INSERT INTO XWLK  VALUES ( '0011','75');
    INSERT INTO XWLK  VALUES ( '0011','80');
    INSERT INTO XWLK  VALUES ( '0012','75');
    INSERT INTO XWLK  VALUES ( '0012','80');
    INSERT INTO XWLK  VALUES ( '0013','75');
    INSERT INTO XWLK  VALUES ( '0013','80');
    INSERT INTO XWLK  VALUES ( '0014','75');
    INSERT INTO XWLK  VALUES ( '0014','80');
    INSERT INTO XWLK  VALUES ( '0015','75');
    INSERT INTO XWLK  VALUES ( '0015','80');
    INSERT INTO XWLK  VALUES ( '0016','75');
    INSERT INTO XWLK  VALUES ( '0016','80');
    INSERT INTO XWLK  VALUES ( '0017','15');
    INSERT INTO XWLK  VALUES ( '0017','70');
    INSERT INTO XWLK  VALUES ( '0018','15');
    INSERT INTO XWLK  VALUES ( '0018','25');
    INSERT INTO XWLK  VALUES ( '0018','70');
    INSERT INTO XWLK  VALUES ( '0019','25');
    INSERT INTO XWLK  VALUES ( '0019','70');
    INSERT INTO XWLK  VALUES ( '0020','70');
    INSERT INTO XWLK  VALUES ( '0021','75');
    INSERT INTO XWLK  VALUES ( '0021','80');
    INSERT INTO XWLK  VALUES ( '0022','75');
    INSERT INTO XWLK  VALUES ( '0022','80');
    INSERT INTO XWLK  VALUES ( '0023','10');
    INSERT INTO XWLK  VALUES ( '0025','05');
    INSERT INTO XWLK  VALUES ( '0025','10');
    INSERT INTO XWLK  VALUES ( '0025','25');
    INSERT INTO XWLK  VALUES ( '0025','30');
    INSERT INTO XWLK  VALUES ( '0025','35');
    INSERT INTO XWLK  VALUES ( '0025','40');
    INSERT INTO XWLK  VALUES ( '0025','45');
    INSERT INTO XWLK  VALUES ( '0025','50');
    INSERT INTO XWLK  VALUES ( '0025','55');
    INSERT INTO XWLK  VALUES ( '0025','60');
    INSERT INTO XWLK  VALUES ( '0025','65');
    INSERT INTO XWLK  VALUES ( '0026','75');
    INSERT INTO XWLK  VALUES ( '0026','80');
    INSERT INTO XWLK  VALUES ( '0027','05');
    INSERT INTO XWLK  VALUES ( '0027','10');
    INSERT INTO XWLK  VALUES ( '0027','25');
    INSERT INTO XWLK  VALUES ( '0027','30');
    INSERT INTO XWLK  VALUES ( '0027','35');
    INSERT INTO XWLK  VALUES ( '0027','40');
    INSERT INTO XWLK  VALUES ( '0027','45');
    INSERT INTO XWLK  VALUES ( '0027','50');
    INSERT INTO XWLK  VALUES ( '0027','55');
    INSERT INTO XWLK  VALUES ( '0027','60');
    INSERT INTO XWLK  VALUES ( '0027','65');
    INSERT INTO XWLK  VALUES ( '0028','15');
    INSERT INTO XWLK  VALUES ( '0069','75');
    CREATE TABLE PTB
       ( PNUM VARCHAR2(20 BYTE));
    INSERT INTO PTB VALUES('003526892');
    INSERT INTO PTB VALUES('06767019');
    INSERT INTO PTB VALUES('14787-10-900');
    INSERT INTO PTB VALUES('003445803');
    INSERT INTO PTB VALUES('000000');
    INSERT INTO PTB VALUES('001645156');
    INSERT INTO PTB VALUES('001646283');
    INSERT INTO PTB VALUES('002587509');
    INSERT INTO PTB VALUES('02507462');
    INSERT INTO PTB VALUES('02565229');
    INSERT INTO PTB VALUES('000943965');
    Query
    SELECT
    SAK.CCODE,
    SAK.CTYPCDE,
    CASE
         WHEN SAK.CCODE = '0001' and SAK.CTYPCDE != '0088' THEN '75'
         WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '75'
         WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '80'
         WHEN SAK.CCODE = '0003' and SAK.CTYPCDE != '0088' THEN '80'
         ELSE XWLK.CODE
    END AS PCD,
    PTB.PNUM
    FROM T1 SAK  INNER JOIN XWLK ON SAK.CTYPCDE = XWLK.CTYPCDE
    INNER JOIN PTB  ON SAK.PNUM = PTB.PNUM
    Order by 4
    Output
    CCODE     CTYPCODE PCD     PNUM
    0002     0018     75     000000
    0002     0018     75     000000
    0002     0018     75     000000
    0025     0007     05     000943965
    0025     0007     10     000943965
    0002     0008     75     001645156
    0002     0008     75     001645156
    0002     0008     75     001646283
    0002     0008     75     001646283
    0025     0008     15     002587509
    0025     0008     20     002587509
    0002     0009     75     003445803
    0001     0007     75     003526892
    0001     0007     75     003526892
    0025     0008     20     02507462
    0025     0008     15     02507462
    0025     0008     15     02565229
    0025     0008     20     02565229
    0001     0006     75     06767019
    0001     0007     75     14787-10-900
    0001     0007     75     14787-10-900
    But the Output is not the expected one if we see for the PNUM = 000000, the records are displayed
    3 times it should be only ones displayed and also for PNUM = 001645156.  My Query is why is it displaying
    more than once, is there anyway that we can display it only once. Can some please advice me where am making
    wrong. Thanks in advance.

    Hi Frank,
    Thanks for your responce. My earlier Insert scripts the sample data had few issues, Please find below the updated one....
    Oracle Version : 10g R2.
    DDL & DML
    CREATE TABLE T1
       (     CCODE VARCHAR2(4 BYTE),
         PNUM VARCHAR2(16 BYTE),
         CTYPCDE VARCHAR2(4 BYTE)
    INSERT INTO T1 VALUES ('0512',     '000-06-5393-05',  '0023');
    INSERT INTO T1 VALUES ('0305',     '000-06-5393-05',  '0006');
    INSERT INTO T1 VALUES ('0611',     '0000',            '0006');
    INSERT INTO T1 VALUES ('0806',     '0000',            '0008');
    INSERT INTO T1 VALUES ('0606',     '0000',            '0006');
    INSERT INTO T1 VALUES ('0099',     '0000',            '0007');
    INSERT INTO T1 VALUES ('0025',     '000000324',       '0008');
    CREATE TABLE XWLK
       (     CTYPCDE VARCHAR2(4 BYTE),
         CODE VARCHAR2(85 BYTE)
    INSERT INTO XWLK  VALUES ( '0004','70');
    INSERT INTO XWLK  VALUES ( '0005','05');
    INSERT INTO XWLK  VALUES ( '0006','05');
    INSERT INTO XWLK  VALUES ( '0007','05');
    INSERT INTO XWLK  VALUES ( '0007','10');
    INSERT INTO XWLK  VALUES ( '0008','15');
    INSERT INTO XWLK  VALUES ( '0008','20');
    INSERT INTO XWLK  VALUES ( '0009','25');
    INSERT INTO XWLK  VALUES ( '0010','75');
    INSERT INTO XWLK  VALUES ( '0010','80');
    INSERT INTO XWLK  VALUES ( '0011','75');
    INSERT INTO XWLK  VALUES ( '0011','80');
    INSERT INTO XWLK  VALUES ( '0012','75');
    INSERT INTO XWLK  VALUES ( '0012','80');
    INSERT INTO XWLK  VALUES ( '0013','75');
    INSERT INTO XWLK  VALUES ( '0013','80');
    INSERT INTO XWLK  VALUES ( '0014','75');
    INSERT INTO XWLK  VALUES ( '0014','80');
    INSERT INTO XWLK  VALUES ( '0015','75');
    INSERT INTO XWLK  VALUES ( '0015','80');
    INSERT INTO XWLK  VALUES ( '0016','75');
    INSERT INTO XWLK  VALUES ( '0016','80');
    INSERT INTO XWLK  VALUES ( '0017','15');
    INSERT INTO XWLK  VALUES ( '0017','70');
    INSERT INTO XWLK  VALUES ( '0018','15');
    INSERT INTO XWLK  VALUES ( '0018','25');
    INSERT INTO XWLK  VALUES ( '0018','70');
    INSERT INTO XWLK  VALUES ( '0019','25');
    INSERT INTO XWLK  VALUES ( '0019','70');
    INSERT INTO XWLK  VALUES ( '0020','70');
    INSERT INTO XWLK  VALUES ( '0021','75');
    INSERT INTO XWLK  VALUES ( '0021','80');
    INSERT INTO XWLK  VALUES ( '0022','75');
    INSERT INTO XWLK  VALUES ( '0022','80');
    INSERT INTO XWLK  VALUES ( '0023','10');
    INSERT INTO XWLK  VALUES ( '0025','05');
    INSERT INTO XWLK  VALUES ( '0025','10');
    INSERT INTO XWLK  VALUES ( '0025','25');
    INSERT INTO XWLK  VALUES ( '0025','30');
    INSERT INTO XWLK  VALUES ( '0025','35');
    INSERT INTO XWLK  VALUES ( '0025','40');
    INSERT INTO XWLK  VALUES ( '0025','45');
    INSERT INTO XWLK  VALUES ( '0025','50');
    INSERT INTO XWLK  VALUES ( '0025','55');
    INSERT INTO XWLK  VALUES ( '0025','60');
    INSERT INTO XWLK  VALUES ( '0025','65');
    INSERT INTO XWLK  VALUES ( '0026','75');
    INSERT INTO XWLK  VALUES ( '0026','80');
    INSERT INTO XWLK  VALUES ( '0027','05');
    INSERT INTO XWLK  VALUES ( '0027','10');
    INSERT INTO XWLK  VALUES ( '0027','25');
    INSERT INTO XWLK  VALUES ( '0027','30');
    INSERT INTO XWLK  VALUES ( '0027','35');
    INSERT INTO XWLK  VALUES ( '0027','40');
    INSERT INTO XWLK  VALUES ( '0027','45');
    INSERT INTO XWLK  VALUES ( '0027','50');
    INSERT INTO XWLK  VALUES ( '0027','55');
    INSERT INTO XWLK  VALUES ( '0027','60');
    INSERT INTO XWLK  VALUES ( '0027','65');
    INSERT INTO XWLK  VALUES ( '0028','15');
    INSERT INTO XWLK  VALUES ( '0069','75');
    CREATE TABLE PTB
       (  PSAK Number(10,0),  
          PNUM VARCHAR2(20 BYTE),
          Seq_num NUMBER(5,0));
    INSERT INTO PTB VALUES('9462003',     '000-06-5393-05', '1');
    INSERT INTO PTB VALUES('9462004',     '000-06-5393-05', '2');
    INSERT INTO PTB VALUES('9462008',     '0000',            '1');
    INSERT INTO PTB VALUES('9462009',     '0000',            '2');
    INSERT INTO PTB VALUES('9462010',     '0000',            '3');
    INSERT INTO PTB VALUES('9462017',     '000000324',       '1');
    Query
    SELECT
    PTB.PSAK,
    CASE
         WHEN SAK.CCODE = '0001' and SAK.CTYPCDE != '0088' THEN '75'
         WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '75'
         WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '80'
         WHEN SAK.CCODE = '0003' and SAK.CTYPCDE != '0088' THEN '80'
         ELSE XWLK.CODE
    END AS PCD,
    PTB.PNUM,
    PTB.Seq_num
    FROM T1 SAK  INNER JOIN XWLK ON SAK.CTYPCDE = XWLK.CTYPCDE
    INNER JOIN PTB  ON SAK.PNUM = PTB.PNUM
    Order by 4,3
    Query output without distinct
    PSAK     PCD     PNUM          SEQ_NUM
    9462003     05     000-06-5393-05     1
    9462003     10     000-06-5393-05     1
    9462008     05     0000          1
    9462008     10     0000          1
    9462008     20     0000          1
    9462008     15     0000          1
    9462008     05     0000          1
    9462008     05     0000          1
    9462017     20     000000324     1
    9462017     15     000000324     1
    9462004     10     000-06-5393-05     2
    9462004     05     000-06-5393-05     2
    9462009     05     0000          2
    9462009     20     0000          2
    9462009     05     0000          2
    9462009     15     0000          2
    9462009     05     0000          2
    9462009     10     0000          2
    9462010     05     0000          3
    9462010     05     0000          3
    9462010     15     0000          3
    9462010     10     0000          3
    9462010     05     0000          3
    9462010     20     0000          3
    Query output with distinct
    PSAK     PCD     PNUM          SEQ_NUM
    9462003     05     000-06-5393-05     1
    9462003     10     000-06-5393-05     1
    9462008     05     0000          1
    9462008     10     0000          1
    9462008     15     0000          1
    9462008     20     0000          1
    9462017     15     000000324     1
    9462017     20     000000324     1
    9462004     05     000-06-5393-05     2
    9462004     10     000-06-5393-05     2
    9462009     05     0000          2
    9462009     10     0000          2
    9462009     15     0000          2
    9462009     20     0000          2
    9462010     05     0000          3
    9462010     10     0000          3
    9462010     15     0000          3
    9462010     20     0000          3
    But both the output is wrong is there any way that i can get the result set as below, from the above query i can see duplicates
    if the PNUM has more SEQ_NUM then it is again doing a cross join i think and hence the result set is coming wrong. The Below
    is the expected output. Can some one help me out in getting this. Thanks in advance.
    PSAK     PCD     PNUM          SEQ_NUM
    9462003     05     000-06-5393-05     1
    9462004     10     000-06-5393-05     2
    9462008     05     0000          1
    9462009     05     0000          2
    9462010     15     0000          3
    9462010     20     0000          3
    9462017     15     000000324                     1
    9462017     20     000000324                     1

  • XML attributes makes my query return no rows

    Hello everyone,
    I've an odd problem.
    I'm querying some XML, but the attributes in one of the tags make my query return no rows; if I remove the attributes, then the query works as expected.
    The XML is below; it's the attributes in the Report tag that cause the issues:
    <result errorCode="0">
         <return>
              <Report
                   xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&amp;rs%3AFormat=xml&amp;rc%3ASchema=True"
                   Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="Items_x0020_status_x0020_information">
                   <Tablix1>
                        <Details_Collection>
                             <Details ItemId="914P7" Username="test" user_role="IT"
                                  first_name="Barry" last_name="Donovan" organisation=""
                                  content_format="On_Screen" modified_date="26/05/2011 13:16:49"
                                  item_status="Draft" status_date="" component_name="" demand="" />
                        </Details_Collection>
                   </Tablix1>
              </Report>
         </return>
    </result>My query is:
         select
                a.item_id
               ,a.username
               ,a.user_role
               ,a.first_name
               ,a.last_name
               ,a.supplier_id
               ,a.format
               ,a.modified_date
               ,a.item_status
               ,a.completion_date
               ,a.component_code
             from   dual
                   ,xmltable
                    ('/result/return/Report/Tablix1/Details_Collection/Details'
                       passing p_xml
                       columns
                          item_id         varchar2(1000) path '@ItemId'
                         ,username        varchar2(1000) path '@Username'
                         ,user_role       varchar2(1000) path '@user_role'
                         ,first_name      varchar2(1000) path '@first_name'
                         ,last_name       varchar2(1000) path '@last_name'
                         ,supplier_id     varchar2(1000) path '@organisation'
                         ,format          varchar2(1000) path '@content_format'
                         ,modified_date   varchar2(1000) path '@modified_date'
                         ,item_status     varchar2(1000) path '@item_status'
                         ,completion_date varchar2(1000) path '@status_date'
                         ,component_code  varchar2(1000) path '@demand'
                    ) a;I've tried stripping out the attributes in the tag, which does work, but some of the XML I'm expecting back may be quite large (many records), so that caused issues in itself. I'd rather deal with it and not mess with the XML itself if possible.
    Any help would be hugely appreciated!
    Thank you very much in advance.
    Robin
    Edited by: User_resU on Apr 12, 2012 2:50 PM

    Example:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<result errorCode="0">
      2     <return>
      3             <Report
      4                     xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&amp;rs%3AFormat=xml&amp;rc%3ASchema=True"
      5                     Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      6                     xmlns="Items_x0020_status_x0020_information">
      7                     <Tablix1>
      8                             <Details_Collection>
      9                                     <Details ItemId="914P7" Username="test" user_role="IT"
    10                                             first_name="Barry" last_name="Donovan" organisation=""
    11                                             content_format="On_Screen" modified_date="26/05/2011 13:16:49"
    12                                             item_status="Draft" status_date="" component_name="" demand="" />
    13                             </Details_Collection>
    14                     </Tablix1>
    15             </Report>
    16     </return>
    17  </result>') as xml from dual)
    18  --
    19  -- end of test data
    20  --
    21       select
    22              a.item_id
    23             ,a.username
    24             ,a.user_role
    25             ,a.first_name
    26             ,a.last_name
    27             ,a.supplier_id
    28             ,a.format
    29             ,a.modified_date
    30             ,a.item_status
    31             ,a.completion_date
    32             ,a.component_code
    33           from   t
    34                 ,xmltable
    35                  (xmlnamespaces('Items_x0020_status_x0020_information' as "x0"),
    36                   '//x0:Report/x0:Tablix1/x0:Details_Collection/x0:Details'
    37                     passing xml
    38                     columns
    39                        item_id         varchar2(1000) path '@ItemId'
    40                       ,username        varchar2(1000) path '@Username'
    41                       ,user_role       varchar2(1000) path '@user_role'
    42                       ,first_name      varchar2(1000) path '@first_name'
    43                       ,last_name       varchar2(1000) path '@last_name'
    44                       ,supplier_id     varchar2(1000) path '@organisation'
    45                       ,format          varchar2(1000) path '@content_format'
    46                       ,modified_date   varchar2(1000) path '@modified_date'
    47                       ,item_status     varchar2(1000) path '@item_status'
    48                       ,completion_date varchar2(1000) path '@status_date'
    49                       ,component_code  varchar2(1000) path '@demand'
    50*                 ) a
    SQL> /
    ITEM_ID
    USERNAME
    USER_ROLE
    FIRST_NAME
    LAST_NAME
    SUPPLIER_ID
    FORMAT
    MODIFIED_DATE
    ITEM_STATUS
    COMPLETION_DATE
    COMPONENT_CODE
    914P7
    test
    IT
    Barry
    Donovan
    On_Screen
    26/05/2011 13:16:49
    Draft

  • Query returns more row than expected

    1. select * from view_name where col1 = 'value1' returns 12 rows
    2. select * from (view script) where col1 = 'value1' returns 24 rows
    i have a view called view_name. If i use view_name directly in the query, it returns 12 rows. But if i use the select script directly in from clause, it returns more rows. I am not able to find out why it is happening so. Any pointers will be helpful.

    Are you saying that the SQL for view_name and view_script are identical? Can you post them?

  • Pl/sql block returning multiple rows

    Hi,
    I've created a plsql block which obtains an id from a name and then uses this id in another sql statement. The select statement to get the id works fine and the correct id is placed into the variable awardID.
    when i try to use this variable in another select statement it returns multiple rows. but when i just use the id in the select statement it works fine.
    select AwardID into awardID
    from award_objtabA
    where Name = awardName;
    this returns the correct id '5999'
    select Points into award_points
    from award_objtabA
    where AwardID = awardID;
    this returns multiple rows
    select Points into award_points
    from award_objtabA
    where AwardID = 5999;
    this works fine
    can anybody help with this confusing error?
    Cheers

    select AwardID
      into awardID               <= the same column
      from award_objtabA
    where Name = awardName;
    this returns the correct id '5999'
    select Points
      into award_points
      from award_objtabA
    where AwardID = awardID;    <= the same column
    this returns multiple rows
    to solve use different name not exactly the same as that of the column name
    select AwardID
      into vAwardID        
      from award_objtabA
    where Name = awardName;
    select Points
      into award_points
      from award_objtabA
    where AwardID = vAwardID;as Alex and Kamal have suggested use different name for your variable.

  • Creating a directory via a jsp page sql query return

    Is it possible to create a directory based on the results of a sql query?
    i.e.
    My sql query returns application number 1234 for a building application (BC for short).
    Is it possible to create a directory /BC/1234
    It is then proposed to use an iframe to look into the directory so users can place and access scanned documents which are captured during the approval process.
    If so how?
    An example would be great.
    Jason

    Sorry hope your still around I've been away for a while. We've created a samber share to the file server where the documents are stored and mounted it within the web file directory. It works ok if there is an existing directory but if there isn't we want it to be created when the page looks for the folder. I've done this with an asp page it basically did a directory exist test first then create folder if it didn't. The problem is can't find an example of how to do the directory exist test then directory create syntax so an example of both would be great

  • SQL query returns varchar - default value type!!!

    On a field in my portal form there is a default value type of 'SQL query returns varchar', where can I put this sql to get a default value from a table?

    Hi again
    I have this code in 'additional pl/sql code' - '...before displaying the page'. But it comes up with an error when I run the form.
    declare
    prop_v varchar2(20);
    group_v varchar2(3);
    el1_v varchar2(3);
    blk varchar2(10) := 'DEFAULT';
    begin
    prop_v := p_session.get_value_as_varchar2(p_block_name=>'DEFAULT', p_attribute_name => 'l_property_p');
    group_v := p_session.get_value_as_varchar2(p_block_name=>'DEFAULT', p_attribute_name => 'l_group_p');
    select element_code
    into el1_v
    from eh_risk_element_detail
    where property_ref = prop_v
    and group_code = group_v
    and line_no = 1;
    p_session.set_value(p_block_name => blk, p_attribute_name => 'L_ELEMENT1_P', p_value => el1_v);
    end;
    Rich

  • [Excel] Running a SQL Query to delete rows

    Hello Experts,
    Background: I am attempting to use a dba of my companies time keeping system and implement it with Power BI tools. Given the file size restrictions within Power Bi itself I need to lower my file size by removing all time logs from
    inactive employees.
    I have a question regarding whether or not you can use a sql query to delete rows in excel. I have roughly 200,000+ rows in my excel spreadsheet. I am attempting to delete all rows where an employee equals inactive. I have attempted to
    delete these rows by sorting them and doing a bulk delete and clear contents, but it seems to crash my excel every time.  My thought process is that using a query that does a timed delete might put less of a burden on deleting the massive amount of data.
    I would like to use this: DELETE * FROM [Table_(...)_Actual$] WHERE [Current] = "Inactive" (Will add more once I know it is possible to use sql queries in Excel.
    Any information on whether or not this is possible would be appreciated.
    Regards,
    Link

    Running SQL Query in Excel is possible, however, the delete query is not supported in Excel.
    You are more restricted in deleting Excel data than   data from a relational data source. In a relational database, "row" has no   meaning or existence apart from "record"; in an Excel worksheet, this is not   true. You can delete values
    in fields (cells). Please see:http://support.microsoft.com/kb/257819/en-us
    One workaround : Use update query to set the rows as null, then use select query.
    e.g. 
    SQL = "update [sheet2$A1:B5] set name=null,age=null where name='andy'"
    cnn.Execute SQL
    SQL = "select name,age from [sheet2$A1:B5] where name is not null"
    Wind Zhang
    TechNet Community Support

  • Query return no rows

    I select a data from one table
    select * from taxon --- it returns rows
    this table has 5 columns -- branchcode, no,trackno,invno,serialno
    if i use the following query
    select * from taxon where branchcode='CNHJCT'
    It return no rwos , but there is data
    if i change the above query like
    select * from taxon where branchcode like '%CNHJCT'
    it returns the rows , but if i check the value of the branchcode there is no space
    on both side .
    How i can troble shoot this problem
    rds

    The is clearly some other characters to the left of the string.
    Look at the output of this query, and you will probably see them.
    SELECT DUMP(branchcode) col, DUMP('CNHJCT') pred
    FROM taxon
    WHERE branchcode LIKE '%CNHJCT'John
    Message was edited by:
    John Spencer
    If I didn't have to re-type everything three times because I can't type, I would have beaten BluShadow :-)

  • Sql query slowness due to rank and columns with null values:

        
    Sql query slowness due to rank and columns with null values:
    I have the following table in database with around 10 millions records:
    Declaration:
    create table PropertyOwners (
    [Key] int not null primary key,
    PropertyKey int not null,    
    BoughtDate DateTime,    
    OwnerKey int null,    
    GroupKey int null   
    go
    [Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
    With the following index:
    CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]    
    [PropertyKey] ASC,   
    [BoughtDate] DESC,   
    [OwnerKey] DESC,   
    [GroupKey] DESC   
    go
    Description of the case:
    For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
    following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
    declare @ownerKey int = 40000   
    select PropertyKey, BoughtDate, OwnerKey, GroupKey   
    from (    
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,       
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]   
    from PropertyOwners   
    ) as result   
    where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
    It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
    May be the slowness is due to as OwnerKey/GroupKey in the table  can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
    view.
    Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.

    create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
    insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
    from PropertyOwners
    go
    declare @ownerKey int = 1
    select PropertyKey, BoughtDate, OwnerKey, GroupKey
    from #result as result
    where result.[Rank]=1
    and result.[OwnerKey]=@ownerKey
    go
    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

  • SQL query in SQL_REDO Logminor showing where clause with ROWID

    SQL query in SQL_REDO Logminor showing where clause with ROWID. I dont wanted to use rowid but wanted to use actual value.
    OPERATION SQL_REDO SQL_UNDO
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2413' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '5' "PROMOTION_ID")
    and "ORDER_TOTAL" = '48552' values ('2413','direct','101',
    and "SALES_REP_ID" = '161' '5','48552','161',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAN';
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2430' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '8' "PROMOTION_ID")
    and "ORDER_TOTAL" = '29669.9' values('2430','direct','101',
    and "SALES_REP_ID" = '159' '8','29669.9','159',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAe';
    Please let me know solution/document which will convert SQL redo rowid value with actual value.
    Thanks,

    Please enclose your output within tag so that people here can read it easily and help you. Also the reason that why you want to remove rowid?
    Salman
    Edited by: Salman Qureshi on Mar 20, 2013 3:53 PM                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to find using SQL query application deployed on win 7 machines with SCCM 2012 server or user installed manually.

    Hi,
    how to find using SCCM SQL query,  application deployed on win 7 machines with SCCM 2012 server or user/technician installed manually. Please let me know.

    Thanks, is it not possible via any script also?
    Like Torsten said, how can you tell the difference between CM12 installed applications and locally installed? Once you can answer that, then you can write report.
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • I am buying a new macbook pro but i want to fit my own ram memory and solid state hard drive , will apple permit this without voiding the waranty.

    i am buying a new macbook pro but i want to fit my own ram memory and solid state hard drive , will apple permit this without voiding the waranty.

    yes you can do it and not void the warranty.  Those are the only hardware changes that Apple permits.  Instructions on how to upgrade the ram and remove and replace the hard drive are even included in the owners manuals for MacBook Pros.

  • Query return no rows in Answers but retrun rows in sql

    Hi all,
    I have the following query which return 3 rows in SQL promple but return no row in Answer and Execute direct request what is the problem any idea?
    select abc_date,abc_asset_desc,sum(abc_market_val_lcy+abc_int_accr_lcy) "Stock"
    from abc
    group by abc_date,abc_asset_descRegards

    Hi,
    i really appriciate your reply
    pls tell me briefly from where i can set log-level > 2 ?? and from where check the physical log of SQL ?
    Followig message is arise at server log
    ORA-01455 converting column overflow integer datatype at OCI call OCIStmtFetch,Bulk fetched failed
    Message was edited by:
    53637

Maybe you are looking for

  • HELP new to mac..

    hi, i have a OneTouch4 Maxtor 500GB external hard drive,USB powered. my external hard drive is partition in 2 halves. half is in use with my time machine for mac os x leopard and the other half is for my vista where i store all my files(music,photos

  • Screen frozen in black iphone 5

    Hy The screen of my iphone 5 frozen in black..seems like my phone no is still ringing as a friend of mine tryed to call me but my phone doesn't do anything..anyone can help me?

  • Can't find history of changes I've made to photos.

    I recently noticed that some previously adjusted photos were no longer linked to Lightroom 5 (in navigatoe, they were grayed out with a questionmark next to them). So I found the photos and imported them to a new folder using "convert to DNG" in the

  • Excess quantaty in Goods Receipt PO

    Dear All, Its really surprising that the receiving quantity can be increase in Goods Receipt PO from Purchase Order quantity. Any one guide me to stop for more receiving then PO thax

  • Wireless + wired printing with Time Capsule?

    I print wirelessly from 2 MacBooks through a Time Capsule to a wireless HP printer, and would also like to print from a non-wireless Vista PC. How do I add the PC to the mix? Thanks for your help!