Using Temp Tables

I'm creating a temp table inside my program. Is there any way to force the database to keep the temp table's contents in memory, rather than flsuhing it to temp disk?

This is nothing to do with temporary tables.
The simplest way is to use UNION operator. This will provide you with the unique combination of rows from the two selects:
select * from test_gtt
union
select '01-07-11 00:00:00',     'level1a',     'level2a', daycount      from gtt_daycount_test
/It's not necessarily the most efficient way of doing things but then, if you're using temporary tables performance probably your num ber one concern.
Cheers, APC

Similar Messages

  • Can't i use temp tables in regions?

    Hi,
    I'm trying to population 3 years fiscal year data in a single row, one for full time and other one for part time employees. So my output should look like this
    Population Fy1_Tot Fy1% Fy2_Tot Fy1% Fy3_Tot Fy3%
    FT 500 50.0 700 70.0 9000 90.0
    PT 500 50.0 300 30.0 1000 10.0
    Each fy1 data represents different month, based on the month I have to populate corresponding Fiscal year and I have take care this.
    I could do this using TEMP table and works well in Toad but not in HTML DB? Can’t I use temp tables in regions?
    Please see the query below
    WITH TEMP AS(
    SELECT INITCAP(FIELD_VALUE) as Population,
    (CASE WHEN D_S_REP.SMC = :P14_MC_FY1 THEN TO_NUMBER(FYT3) END) as Total1,
    (CASE WHEN D_S_REP.SMC = :P14_MC_FY1 THEN FYP3 END) as FY1P,
    (CASE WHEN D_S_REP.SMC = :P14_MC_FY2 THEN TO_NUMBER(FYT2) END) as Total2,
    (CASE WHEN D_S_REP.SMC = :P14_MC_FY2 THEN FYP2 END) as FY2P,
    (CASE WHEN D_S_REP.SMC = :P14_MC_FY3 THEN TO_NUMBER(FYT1) END) as Total3,
    (CASE WHEN D_S_REP.SMC = :P14_MC_FY3 THEN FYP1 END) as FY3P
    FROM D_S_REP
    WHERE FIELD_NAME='POPULATION'
    AND RS_YR LIKE '%'||TRIM(:P14_S_YR) || '%'
    AND D_S_REP.SMC IN (TRIM(:P14_MC_FY1),TRIM(:P14_MC_FY2),TRIM(:P14_MC_FY3))
    AND WP_NAME = TRIM(:P14_WP_NAME)
    AND RDL_NAME LIKE '%'||TRIM(:P14_EMPLOYEES)||'%'
    GROUP BY FIELD_VALUE,D_S_REP.SMC, FYT3,FYP3,FYT2,FYP2,
    FYT1,FYP1)
    SELECT Population, SUM(Total1), SUM(FY1P), SUM(Total2), SUM(FY2P),SUM(Total3), SUM(FY3P) FROM TEMP
    GROUP BY Population
    Any thoughts!!
    Thanks
    CK

    Actually the same query works well, in HTML DB too. it was my fault i placed the query in a wrong region so i was getting error..
    Thanks

  • DESKI Report using Temp tables in MS- SQL server 2005

    Hi,
    I am trying to create a Free hand SQL DESKI report using temp tables in MS SQL Server-2005, I am using ODBC connection.
    When I run the report, I am getting the error
    u201CConnection or SQL sentence error (DA0005) No column or data to fetchu201D
    Ex:
    Select *
    into #t1
    from region
    select * from #t1
    drop table #t1
    Please help.
    Regards,
    Pratik

    Pratik, the SQL does not seem right. BTW you can only retreive data via Deski Free hand SQL. Also try to use OLE DB connection.

  • Stored Procedure uses Temp Tables

    C#, asp.net app.
    I have a stored procudure that outputs data to temp tables. The data in these tables is only there for the life of that connection. The stored procedure does NOT return data.
    Options I see so far:
    1) If I open a connection and execute the stored procudure, how can I get crystal to use the SAME connection object?
    2) Can I get crystal to call the stored procedure for me first (but remember, it doesn't use the sp as the actual data source). Would I still be able to supply parameters to the SP?
    3) I guess I could do everything myself, even load all the data out of the temp tables into local datasets. And then supply the datasets to the tables. I tried this and I called SetDataSource on all my tables but then it looks like it still tried to go to the server again as I got a login screen.

    Hello Happy,
    No, Crystal does not have any access to those temp tables. They are locked by the owner who made the call and we have no API available in .NET that you can ride on to get access. Unless you can figure out a way at runtime to give full permission to the temp table then CR can use it. You just need to set the datasource to the temp table name at runtime. You will need to create the table so a report can be designed off it first but once done as long as the structure doesn't change the report will continue to work.
    Other options are as you have tried using data sets. Another option is to export that data into a database so CR has access to it rather than using temp tables. Once the report is done you can use MS API's to delete all rows of data.
    Thank you
    Don

  • How to use temp table/variable

    Hello,
    It's SQL 2008 R2. I need to bring data from Oracle using .Net Providers/ODBC Data Provider to MS SQL table converting Oracle UTC dates to PST.  The source connection type cannot be changed as it's given. For the Destination I'm using the OLE DB.
    As the truncate all and load could take time I'm trying to use a temp table or a variable to use it further with t-sql merge or not exists to bring/add the only new records to the destination table.
    I'm trying different scenarios that is all failed.
    Scenario A:
    1. In DTF after OLE DB Source I'm using the Derived Colum to convert dates. It's working well.
    2. Then use Recordset Destination with an object variable User::obj_TableACD. It's also working well.
    3. Then I created a string variable with a simple query that I could modify later "select * from " + (DT_WSTR,10)@[User::obj_TableACD] trying to get data from the recordset object variable but it's not working.
    Scenario B:
    1. Created a store procedure to create a temp table.
    2. Created a string variable to execute SP str_CreateTempTable: "EXEC dbo.TempTable". It's working well with the SQL Task with SQLSourceType as Variable.
    3. Then how to populate the temp table from the Oracle source to bring data into the Destination?
    I could spend another few days to figure it out. So, please help me on it if there is a way to solve it.
    Thanks

    Thank you so much, Nitesh. Now, I got the understanding of temp tables in SSIS. However, in my case to implement t-sql merge or not exists to bring the new records only I'd need to load at least a one table into a temp table anyway. So, why not to use a
    destination table instead. I also noticed a one remark from the article you suggested that the expert who wrote the article had never actual used the temp tables in SSIS.
    So, I decided to go with truncate, drop keys, derive columns, load, and create keys again in the destination table.
    Thank you again, I'll reserve the knowledge I got for the temp SSIS tables for some other cases.

  • Stored procedure call returns null result set when using temp table in sp!

    Here's a really odd problem...
    SQL Server stored procedure called sp_Test takes 1 input INT. Here is the code I call it with
    cStmt = connection.prepareCall("{call sp_Test(?)}");
    cStmt.setInt(1, 44);
    cStmt.execute();
    rs = cStmt.getResultSet();When the body of the stored proc is
    CREATE PROCEDURE sp_Test(@i_NodeID INT)
    AS
    BEGIN
      SELECT node_id FROM tbl_NavTree
    END
    GOthe query works and I get all node_id back in rs
    BUT when the body of the stored proc is
    CREATE PROCEDURE sp_Test(@i_NodeID INT)
    AS
    BEGIN
      CREATE TABLE #Descendants(
        descendant_id INT
      SELECT node_id FROM tbl_NavTree
      DROP TABLE #Descendants
    END
    GOThe rs comes back as NULL. Really really weird if you ask me. I also tried removing the DROP TABLE line just in case the SELECT had to be the last statement but still NULL.
    Final note is that BOTH the above stored proc bodies work when executed within SQL Server query analyser.
    Must be JDBC .. what can it be!??

    DROP TABLE #DescendantsMS SQL Server - right?
    Then don't drop the table.
    From the MS docs for "create table"
    Local temporary tables are visible only in the current session;
    A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table.

  • Please help - Can not use stored procedure with CTE and temp table in OLEDB source

    Hi,
       I am going to create a simple package. It has OLEDB source , a Derived transformation and a OLEDB Target database.
    Now, for the OLEDB Source, I have a stored procedure with CTE and there are many temp tables inside it. When I give like EXEC <Procedure name> then I am getting the error like ''The metadata  could not be determined because statement with CTE.......uses
    temp table. 
    Please help me how to resolve this ?

    you write to the temp tables that get created at the time the procedure runs I guess
    Instead do it a staged approach, run Execute SQL to populate them, then pull the data using the source.
    You must set retainsameconnection to TRUE to be able to use the temp tables
    Arthur My Blog

  • Temp Tables - Best Practice

    Hello,
    I have a customer who uses temp tables all over their application.
    This customer is a novice and the app has its roots in VB6. We are converting it to .net
    I would really like to know the best practice for using temp tables.
    I have seen code like this in the app.
    CR2.Database.Tables.Item(1).Location = "tempdb.dbo.[##Scott_xwPaySheetDtlForN]"
    That seems to work, though i do not know why the full tempdb.dbo.[## is required.
    However, when i use this in the new report I am doing I get runtime errors.
    i also tried this
    CR2.Database.Tables.Item(1).Location = "##Scott_xwPaySheetDtlForN"
    I did not get errors, but I was returned data i did not expect.
    Before i delve into different ways to do this, i could use some help with a good pattern to use.
    thanks

    Hi Scott,
    Are you using the RDC still? It's not clear but looks like it.
    We had an API that could piggy back the HDBC handle in the RDC ( craxdrt.dll ) but that API is no longer available in .NET. Also, the RDC is not supported in .NET since .NET uses the framework and RDC is COM.
    Work around is to copy the temp data into a data set and then set location to the data set. There is no way that I know of to get to the tempdb from .NET. Reason being is there is no CR API to set the owner of the table to the user, MS SQL Server locks the tempdb to that user has exclusinve rights on it.
    Thank you
    Don

  • How to read the data file and write into the same file without a temp table

    Hi,
    I have a requirement as below:
    We are running lockbox process for several business, but for a few businesses we have requirement where in we receive a flat file in different format other than how the transmission format is defined.
    This is a 10.7 to 11.10 migration. In 10.7 the users are using a custom table into which they are first loading the raw data and writing a pl/sql validation on that and loading it into a new flat file and then running the lockbox process.
    But in 11.10 we want to restrict using temp table how can we achieve this.
    Can we read the file first and then do validations accordingly and then write to the same file and process the lockbox.
    Any inputs are highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

    Hello Gurus,
    Let me tell you about my requirement clearly with an example.
    Problem:
    i am receiving a dat file from bank in below format
    105A371273020563007 07030415509174REF3178503 001367423860020015E129045
    in this detail 1 record starting from 38th character to next 15 characters is merchant reference number
    REF3178503 --- REF denotes it as Sales Order
    ACC denotes it as Customer No
    INV denotes it as Transaction Number
    based on this 15 characters......my validation comes.
    If i see REF i need to pick that complete record and then fill that record with the SO details as per my system and then submit the file for lockbox processing.
    In 10.7 they created a temporary table into which they are loading the data using a control file....once the data is loaded into the temporary table then they are doing a validation and updating the record exactly as required and then creating one another file and then submitting the file for lockbox processing.
    Where as in 11.10 they want to bypass these temporary tables and writing it into a different file.
    Can this be handled by writing a pl/sql procedure ??
    My findings:
    May be i am wrong.......but i think .......if we first get the data into ar_payments_interface_all table and then do the validations and then complete the lockbox process may help.
    Any suggestions from Oracle GURUS is highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

  • Global Temp Table Not found - SSIS

    I am facing below error while using global temp table in SSIS.
    [OLE DB Destination [78]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E37.
    An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 10.0"  Hresult: 0x80040E37  Description: "Table/view either does not exist or contains errors.".
    [OLE DB Destination [78]] Error: Failed to open a fastload rowset for " ##AGENTDTLS". Check that the object exists in the database.
    [SSIS.Pipeline] Error: component "OLE DB Destination" (78) failed the pre-execute phase and returned error code 0xC0202040.
    1) For data connection manager - Retain same connection is set to True
    2) Data Flow task - Delay Validation is set to True
    3) Destination Task - Using Temp Table - ValidateExternalMetadata is set to false.
    4) I am just using one data connection.
    5) before using the temp file I am checking if its exits and if yes drp it first and create it.
    Not able to understand the reason for failure.

    Why don't you use permanent table in tempdb?
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Issue with Temp tables in SSIS 2012 with RetainSameConnection=true

    Hello,
    We have few packages written in 2008 and are being upgraded to 2012. Our package mostly uses temp tables during the process.  During initial migration, we faced issue with handling temp table in the OLE Db destination provider and found a solution for
    the same under 
    usage of Temp tables in SSIS 2012
    Most of our packages execute fine now. 
    we came across a different issue recently. For one of our package, which merges 3 feeds into a temp table and then executes a stored procedure for processing, the package fails intermittently.
    Below are properties of SSIS and its components, which you might be interested
    * Retainsameconnection for the OLE Db connection manager set to True
    * properties of OLEDB Destination 
    AccessMode : SQL Command
    CommandTimeOut : 0
    SQLCommand : Select * from #tmp
    * using SSIS 2012 and SQL OLEDB Native Provider 11 (Provider=SQLNCLI11.1)
    * one of the feed is 10MB
    During investigation using profiler, found that though I use RetainSameConnection, I often  could see that more than one SPId is used during the scope of SSIS execution and when ever this happens, package fails with below error message 
    An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E14 Description: "Statement(s) could not be prepared.".
    An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E14 Description: "Invalid object name '#tmp'."
    Now, Why SSIS uses a different SPId during its execution when RetainSameconnection is set to True (note : I have only one OLEDB connection in that package)? 
    To simulate the issue, Instead of 10MB file, I used a 500KB file and execute the package twice and all went fine.
    Is it because of 10 MB file taking long time to process causing the time out of that OLEDB destionation forcing the SSIS to go for another connection? but remember, CommandTimeout is set to infinite(0) for that OLEDB destination. 
    Much appreciated your response. 

    Hey,
    I understand you used Retainsameconnection property true for all the OLEDB connections you used in the package if not make sure its for all the connection including file connection as well.
    Additionally, you can try to set Delayvalidation property to true for all the dataflows and control flows in the connection and try running the package for 10MB file.
    I hope this will fix the intermittent failure issue you are facing with SSIS.
    (Please mark solved if I've answered your question, vote for it as helpful to help other user's find a solution quicker)
    Thanks,
    Atul Gaikwad.

  • How to work on temp table in oracle 10g

    Hi Guys,
    I have one simple procedure and it is returning some records through dbms_output.put_line.
    cursor c1 is select object_name from t_Turbo;
    type c1_type is table of c1%rowtype;
    rec1 c1_type;
    begin
    open c1;
    loop
    fetch c1 bulk collect into rec1 limit 200;
    for i in 1..rec1.count loop
    dbms_output.put_line(rec1.i);
    end loop;
    exit when c1%notfound;
    end loop;
    end;
    Now i am plaing to use temp table at dmbs_output.put_line in place and from there I want to select the records.
    Can any one help me on this.
    Thanks in advance!
    Regards,
    KLR

    This is what you need.
    create or replace procedure test ( pRet out sys_refcursor )
    as
    begin
      open pRet for select object_name from t_Turbo;
    end;SYS_REFCURSOR is a cursor type defined by oracle. You can define your owner.

  • Temp Table in view

    I Know we cannot use Temp table,table variable in View but i want to know the reason behind it

    Assuming the second batch is executed from a 2nd connection, there is no doubt that the query should return 46 on that 2nd connection. If the 1st connection would run the same SELECT statement, it should return 33.
    And if the definition of the temp tables are
    CREATE TABLE #temp(a int NOT NULL)
    CREATE TABLE #temp(b float NOT NULL)
    Keep in mind how view definitions are stored in SQL Server.
    I don't know exactly why the original poster wanted this, but what does make sense is of course a temporary view, and preferrably one that does not require a batch of its own. A couple of years ago, I wrote a stored procedure where I found that I repeated
    the same conditions all over again. This made me year for something like a module-level CTE and I submitted this Connect item:
    http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=343067
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Usage of Temp tables in SSIS 2012

    Hello,
    We have many SSIS packages (2008 R2) which imports data to a temp table and process it from there. 
    We are upgrading to SQL server 2012 and facing the issue with temp table as working table and our ssis packages fail in 2012. While investigating found that SQL Server 2012 deprecates FMTONLY option
    and instead uses
    sp_describe_first_result_set , which does not support using of temp tables as import table.  SSIS works fine in our workstations but not in the DEV box.  With SQL 2012, I can execute from my workstation, which has (11.0.2100.60) where as DEV server
    has SQL Server version 11.0.3000.0 
    Also when I ran profile with that of the DEV box, it gives two different statements 
    from workstation (11.0.2100.60)
    CREATE TABLE #temp (
    Id varchar(255) NULL,
    Name varchar(255) NULL )
    go
    declare @p1 int
    set @p1=NULL
    declare @p3 int
    set @p3=229378
    declare @p4 int
    set @p4=294916
    declare @p5 int
    set @p5=NULL
    exec sp_cursoropen @p1 output,N'select * from #temp',@p3 output,@p4 output,@p5 output
    select @p1, @p3, @p4, @p5
    go
    it works fine
    But with the DEV server (version 11.0.3000.0), it executes the below sql and it fails to get the meta data
    CREATE TABLE #temp (
    Id varchar(255) NULL,
    Name varchar(255) NULL )
    exec [sys].sp_describe_first_result_set N'select * from [dbo].[#temp]'
    On checking the assembly difference between the versions, I could only see Microsoft.SqlServer.ManagedDTS.dll being 11.0.3000.0, which I replace by 11.0.2100.60 version. but still getting the same result. 
    The other different I found is with ,Net framework libraries.
    Could you advise whats the assembly causing this issue between our workstation and DEV server  i.e 11.0.2100.60 and 11.0.3000.0 
    Many thanks

    Scripts are taken from profiler.
    The error message is 
    The metadata could not be determined because statement 'Select * from #branchscan' uses a temp table. 
    I could see the work around saying use of table variable and global temp tables.  We are having around 100+ ssis packages which uses temp table for loading the data from a flat file and respective SP to process the data from the temp table.  above
    error is thrown during the pre-execute phase of the OLE db Destination, when trying to get the meta data of the table. 
    At this stage, it would be difficult for us to change the logic to global temp or TVP
    Thanks

  • Temp Tables in Oracle?

    Hi.
    Where can i find information abount using temp tables in Oracle?
    I usually work with SQL Server and use temp tables. I don't have any idea about temp tables in Oracle. Could you give me any information?
    Thanks.
    I'm sorry for may english, I'm spanish.

    There are two completely different things being discussed here temporary segments used by Oracle's internal processes and Oracle global temporary tables.
    Or did I misunderstand?
    We have used Oracle's global temporary tables as quick staging array while data is being integrated into finance apps. Testing showed the process performed faster with this design.
    Both temporary segments and Oracle's global temporary tables are stored in the TEMP tablespace.

Maybe you are looking for

  • Why does my iMac keep waking every 2 minutes from 2:00 in the morning?

    Hi, I awoke the other night and happened to notice my iMac keeps waking from sleep every 2 minutes from 2:00 in the morning. The screen doesn't come on, I hear the harddrive power up for a little while then stop, 2 minutes later it happens again. I d

  • Find user SAP Portal role in an abap program

    Dear all, We would like to check the SAP Portal role of a Portal user in a R/3 abap program. do you know if there is a bapi or a RFC module function to do that ? For example : the user CCDEMO (exists in EP and in R/3 backend) has a Buyer Portal role.

  • Logic and pro tools transfer  with OMF or AAF

    Hi has anybody experience with the transfer from Pro Tools 6.9 session into LOGIC 7.1 and back to PT via OMF or AAF ?? I need to know if this is really working now and what about the tdm/rtas plug ins and delay-compensation??? would be nice if somebo

  • Requirement to have 3 hyper-v in Windows Server 2012 R2 Std

    Hi, I want to configure three Hyper-V in my Windows Server 2012 R2 Standard. 1. ERP System 2. Mail Server 3. AD What requirement or license do I need to have? Thank You.

  • Multichannel video record

    I´m looking for a multichannel video capture card or device and software for mac... I will check 20 video and audio feeds (networks) at the same time so I have to record the feed comming from a radio walman but with 20 radios at the same time plus so