How to Create a Temporary Table with SQL Server

I know you can create a temporary table in SQL Server 2000, but not quite sure how to do it in CFMX 7, i.e., does the SQL go inside a <CFQUERY dbtype="query"> tag?
I'm pulling the main set of records from an Oracle server (1st data source), but it does not contain employee names, only employee IDs.  Since I need to show the employee name along with the Emp ID, I'm then pulling a list of "current" employee names from a SQL Server (2nd data source), which is the main database on our CF server.
I've got a QofQ that works fine, except it only matches EmpIDs that exist in both result sets.  Employees who are no longer employed, don't match, and don't display.  Since I can't do a LEFT OUTER JOIN with a QofQ, what I need to do is get the records from the Oracle server into the SQL Server.  Preferably in a temporary table.
I was hoping if I could get those Oracle records written to a temp table on the main SQL Server, in same database as the Employee Name table, I could then write a normal <CFQUERY> that uses a LEFT OUTER JOIN.
I think I could probably write a Stored Procedure that would execute the SQL to create the temporary table, but am trying to avoid having to write the SP, and do it the simplest way.
This query will be a program that can be run hundreds of times per day, with a form that allows users to select date ranges, locations, and other options.  That starts the queries, which creates the report.  So I just need the temp table to exist only until all the SQL has run, and the <CFOUTPUT> has generated a report.
If the premise is right, I just need some help with the syntax for creating a SQL Server temp table, when you want to write records to it from an external data source.  I'm trying the following, but getting an error:
<CFQUERY name="ITE_Temp" datasource="SkynetSQL">
CREATE TABLE #MyTemp
(   INSERT INTO #MyTemp
ITE2.TrueFile char (7) NOT NULL,
ITE2.CountOfEmployee int NULL,
ITE2.DTL_SUBTOT decimal NULL,
ITE2.EMPTYPE char (3) NULL,
ITE2.ARPT_CD char (3) NULL
</CFQUERY>
So I actually created a permanent table on the SQL Server, and wrote the below SQL, which does work, and does write the records to table.  I can then write another CFQUERY with a LEFT OUTER JOIN, and get all the records, including those that don't have matching employee name:
<CFQUERY datasource="SkynetSQL">
<CFLOOP index="i" from="1" to = "#ITE2.RecordCount#">
INSERT INTO ITE_Temp
   (FullFile,
   EmployeeCount,
   DTL_Amount,
   EmployeeType,
   station)
VALUES  ('#ITE2.TrueFile[i]#',
   #ITE2.CountOfEmployee[i]#,
   #ITE2.DTL_SUBTOT[i]#,
   '#ITE2.EMPTYPE[i]#',
   '#ITE2.ARPT_CD[i]#')
</CFLOOP>
</CFQUERY>
But, I hate to have to create a table and physically write to it.  For one, it seems slower, and doing it in temp would be in memory, and probably much faster, correct?  Is there some way to code the above, so that it does something similar, but in a TEMPORARY TABLE?   If I can figure out how to do this, I can pull data from multiple data sources and servers, and using SQL Server temp tables, work with the data as if it was all on the same SQL Server, and do some cool reports.
Everything I've done for the past few years, has all been from data from a single source, whether SQL Server, or another server.  Now I need to start writing reports where data can come from 3 or 4 different servers, and be able to do joins (inner and outer).  Thanks for any advice/help.  Much appreciated.
Gary

While waiting to hear back, I was able to write the query results from an outside Oracle server, to a table on the local SQL Server, and do the LEFT OUTER JOIN required for the final query and report to work.  That was with this syntax:
<CFQUERY name="AddTableRecords" datasource="MyTable">
TRUNCATE TABLE ITE_Temp
<CFOUTPUT query="ITE2">
INSERT INTO ITE_Temp
(FullFile,EmployeeCount,DTL_Amount,EmployeeType,station)
VALUES
('#TrueFile#', #CountOfEmployee#, #DTL_SUBTOT#, '#EMPTYPE#', '#ARPT_CD#')
</CFOUTPUT>
</CFQUERY>
However, I was not able to write to a temporary table AND read the results. I got the syntax to run to write the above results to a temporary table.  But when I tried to read and output the results from the temp table, I got an error.  Also, it wouldn't take the single "#" (local) only the global "##" table var, using this syntax.  Note that if I didn't have the DROP TABLE in the beginning, the 2nd time you run this query, you get an error telling you the table already exists.
<CFQUERY name="ITE_Temp2" datasource="MyTable">
DROP TABLE ##MyTemp2
CREATE TABLE ##MyTemp2
FullFile char (7) NOT NULL,
EmployeeCount int NULL,
DTL_Amount decimal NULL,
EmployeeType char (3) NULL,
station char (3) NULL
<CFOUTPUT query="ITE2">
INSERT INTO ##MyTemp2 VALUES
'#ITE2.TrueFile#',
#ITE2.CountOfEmployee#,
#ITE2.DTL_SUBTOT#,
'#ITE2.EMPTYPE#',
'#ITE2.ARPT_CD#'
</CFOUTPUT>
</CFQUERY>
So even though the above works, I could use some help in reading/writing the output.  I've tried several things similar to below, but they don't work.  It't telling me ITE_Temp2 does not exist.  It's not easy to find good examples of creating temporary tables in SQL Server.
<CFQUERY name="QueryTest2" datasource="SkynetSQL">
SELECT *
FROM ITE_Temp2
</CFQUERY>
<CFOUTPUT query="ITE_Temp2">
Output from Temp Table<br>
<p>FullFile: #FullFile#, EmployeeCount: #EmployeeCount#</p>
</CFOUTPUT>
Thanks for any help/advice.
Gary.

Similar Messages

  • How to create a cutoms table with a heading

    Dear Freinds,
    I have a requirement where i have to create the Custom as below .........my functional is
    saying that he want table as below
                                              outpatient  
    employeeno
    class
    startdate
    enddate
    spouse
    1stchild
    2nchild
    How can we create like this table having outpatient  as heading
    and a fields  as
    employeeno , class,startdate,enddate,spouse,1stchild,2ndchild
    how can we create in a custom table..... i have never seenlike the above requiremnt.
    Please suggest me how to create. I can send the Excel sheet where they have given the above requiremnt...... plelase any body can suggest me so that i can your personnel id's . Pleast a bit urgent.
    regards
    syamala

    While waiting to hear back, I was able to write the query results from an outside Oracle server, to a table on the local SQL Server, and do the LEFT OUTER JOIN required for the final query and report to work.  That was with this syntax:
    <CFQUERY name="AddTableRecords" datasource="MyTable">
    TRUNCATE TABLE ITE_Temp
    <CFOUTPUT query="ITE2">
    INSERT INTO ITE_Temp
    (FullFile,EmployeeCount,DTL_Amount,EmployeeType,station)
    VALUES
    ('#TrueFile#', #CountOfEmployee#, #DTL_SUBTOT#, '#EMPTYPE#', '#ARPT_CD#')
    </CFOUTPUT>
    </CFQUERY>
    However, I was not able to write to a temporary table AND read the results. I got the syntax to run to write the above results to a temporary table.  But when I tried to read and output the results from the temp table, I got an error.  Also, it wouldn't take the single "#" (local) only the global "##" table var, using this syntax.  Note that if I didn't have the DROP TABLE in the beginning, the 2nd time you run this query, you get an error telling you the table already exists.
    <CFQUERY name="ITE_Temp2" datasource="MyTable">
    DROP TABLE ##MyTemp2
    CREATE TABLE ##MyTemp2
    FullFile char (7) NOT NULL,
    EmployeeCount int NULL,
    DTL_Amount decimal NULL,
    EmployeeType char (3) NULL,
    station char (3) NULL
    <CFOUTPUT query="ITE2">
    INSERT INTO ##MyTemp2 VALUES
    '#ITE2.TrueFile#',
    #ITE2.CountOfEmployee#,
    #ITE2.DTL_SUBTOT#,
    '#ITE2.EMPTYPE#',
    '#ITE2.ARPT_CD#'
    </CFOUTPUT>
    </CFQUERY>
    So even though the above works, I could use some help in reading/writing the output.  I've tried several things similar to below, but they don't work.  It't telling me ITE_Temp2 does not exist.  It's not easy to find good examples of creating temporary tables in SQL Server.
    <CFQUERY name="QueryTest2" datasource="SkynetSQL">
    SELECT *
    FROM ITE_Temp2
    </CFQUERY>
    <CFOUTPUT query="ITE_Temp2">
    Output from Temp Table<br>
    <p>FullFile: #FullFile#, EmployeeCount: #EmployeeCount#</p>
    </CFOUTPUT>
    Thanks for any help/advice.
    Gary.

  • How to create database and table with GUI?

    How to create database and table with GUI?
    for linux can do that?
    or have only way to create table by use sql*plus.
    everyone please help me.
    thanks

    go to www.orasoft.org
    here is a gui tool.
    null

  • How to create user defined metrics for SQL Server target?

    The customer is not able to create a user defined metrics for SQL Server target.
    This is very important for him to use this product.
    He is asking how to create user defined metrics?
    I sent him Note 304952.1 How to Create a User-Defined SQL Metric in EM 10g Grid Control
    But it would work for an Oracle DB, but his target is SQL Server DB
    Not able to find the "User-Defined Metrics" link from Database home page.
    How to create user defined metrics for SQL Server target?

    http://download-uk.oracle.com/docs/cd/B14099_19/manage.1012/b16241/Monitoring.htm

  • How to process each records in the derived table which i created using cte table using sql server

    I want to process each row from the CTE table I created, how can I traverse from first row to second row and so on....
    how to process each records in the derived table which i created using  cte table using sql server

    Ideally you would be doing a set based processing rather than traversing row by row as thats more efficient. To answer it specific to your scenario we may need more info. Can you explain with some sample data your exact requirement?
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to use create-default-dbms-tables in SQL Server 2000

    Hi everyone,
    I'm new in EJB development. I'm trying to deploy a CMP to Weblogic 8.1 SP1 using
    JBuilderX. I configured a ConnectionPool and DataSource to allow the CMP to access
    the SQL Server 2000. However, I cannot deploy the CMP if I didn't create the table
    in SQL Server manually. Does anyone know how to use the create-default-dbms-tables?

    Refer to
    http://e-docs.bea.com/wls/docs81/ejb/DDreference-cmp-jar.html#1162249
    "Keith" <[email protected]> wrote:
    >
    Hi everyone,
    I'm new in EJB development. I'm trying to deploy a CMP to Weblogic 8.1
    SP1 using
    JBuilderX. I configured a ConnectionPool and DataSource to allow the
    CMP to access
    the SQL Server 2000. However, I cannot deploy the CMP if I didn't create
    the table
    in SQL Server manually. Does anyone know how to use the create-default-dbms-tables?

  • How to create a TEMPORARY table in memory?

    Hi,
    Is there any way to create a temporary table in memory other than in tablespce?

    A cursor should do the job for you, I reckon.
    Regards,
    Raymond.

  • How to create conditional update trigger in sql server

    How to create conditional update trigger in sql server

    You cant create a conditional update trigger. Once you create an update trigger it will get called for every update action. However you could write logic inside it to make it do your activity based on your condition using IF condition statement
    Say for example if you've table with 6 columns and you want some logic to be implemented on update trigger only if col3 and col5 are participating in update operation you can write trigger like this
    CREATE TRIGGER Trg_TableName_Upd
    ON TableName
    FOR UPDATE
    AS
    BEGIN
    IF UPDATE(Col3) OR UPDATE (Col5)
    BEGIN
    ....your actual logic here
    END
    END
    UPDATE() function will check if column was involved in update operation and returns a boolean result
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to create Dynamic internal table with columns also created dynamically.

    Hi All,
    Any info on how to create a dynamic internal table along with columns(fields) also to be created dynamically.
    My requirement is ..On the selection screen I enter the number of fields to be in the internal table which gets created dynamically.
    I had gone thru some posts on dynamic table creation,but could'nt find any on the dynamic field creation.
    Any suggestions pls?
    Thanks
    Nara

    I don't understand ...
    something like that ?
    *   Form P_MODIFY_HEADER.                                              *
    form p_modify_header.
      data : is_fieldcatalog type lvc_s_fcat ,
             v_count(2)      type n ,
             v_date          type d ,
             v_buff(30).
    * Update the fieldcatalog.
      loop at it_fieldcatalog into is_fieldcatalog.
        check is_fieldcatalog-fieldname+0(3) eq 'ABS' or
              is_fieldcatalog-fieldname+0(3) eq 'VAL' .
        move : is_fieldcatalog-fieldname+3(2) to v_count ,
               p_perb2+5(2)                   to v_date+4(2) ,
               p_perb2+0(4)                   to v_date+0(4) ,
               '01'                           to v_date+6(2) .
        v_count = v_count - 1.
        call function 'RE_ADD_MONTH_TO_DATE'
            exporting
              months        = v_count
              olddate       = v_date
            importing
              newdate       = v_date.
        if is_fieldcatalog-fieldname+0(3) eq 'ABS'.
          concatenate 'Quantité 0'
                      v_date+4(2)
                      v_date+0(4)
                      into v_buff.
        else.
          concatenate 'Montant 0'
                      v_date+4(2)
                      v_date+0(4)
                      into v_buff.
        endif.
        move : v_buff to is_fieldcatalog-scrtext_s ,
               v_buff to is_fieldcatalog-scrtext_m ,
               v_buff to is_fieldcatalog-scrtext_l ,
               v_buff to is_fieldcatalog-reptext .
        modify it_fieldcatalog from is_fieldcatalog.
      endloop.
    * Modify the fieldcatalog.
      call method obj_grid->set_frontend_fieldcatalog
           exporting it_fieldcatalog = it_fieldcatalog.
    * Refresh the display of the grid.
      call method obj_grid->refresh_table_display.
    endform.                     " P_MODIFY_HEADER

  • How to create an internal table with fields from different sources

    Hi.
    I need to create an internal table where some of the fields are from a database table, and the other fields are user specified. How do i do that?
    Example:
    DB table ZTAB with fields ZTAB-FIELD1, ZTAB-FIELD2.
    I want to create an internal table ITAB with the fields ZTAB-FIELD1, ZTAB-FIELD2 from ZTAB. In addition, I also want to have one more field RECORD_NO, which is not from ZTAB. How do I do it? Could I do something like below?
    DATA BEGIN OF ITAB.
            INCLUDE STRUCTURE ZTAB.
    DATA RECORD_NO TYPE I.
    DATA END OF UPLINE.
    Or, are there more efficient way of doing it? Thanks.

    hi KIan,
    go:
    general type
    TYPE : BEGIN OF ty_itab,
               field1 TYPE ztab-field1,
               field2 TYPE ztab-field2,
    *your own fields here:
               field TYPE i,
               field(30) TYPE c,
               END OF ty_itab.
    work area
    DATA : gw_itab TYPE ty_itab.
    internal table
    DATA : gt_itab TYPE TABLE OF ty_itab.
    hope this helps
    ec

  • How to create an internal table with a types structure?

    Hi experts,
    I've 3 internal tables with the same structure, I think I could put a type structure and put that type inside the body of the internal data, is this possible? If true, how can I put that?
    Example:
    TYPES: Begin of type_s,
                   pernr like pa0001-pernr,
                 end of type_s.
    Data: begin of itab_1 occurs 0,
    ¿¿¿??? reference to type_s
             end of itab_1.
    Thanks a lot,
    Regards,
    Rebeca

    Hi,
    Use like this..
    DATA: Begin of type_s,
    pernr like pa0001-pernr,
    end of type_s.
    DATA: BEGIN OF ITAB_1 OCCURS 0.
    INCLUDE STRUCTURE type_s.
    DATA: END OF ITAB_1.
    Otherwise like this.
    types: Begin of type_s,
    pernr like pa0001-pernr,
    end of type_s.
    Data: itab_1 type standard table of type_s.
    Note: You have to create work area explicitly.
    Like this
    data wa like itab1.
    Edited by: Velangini Showry Maria Kumar Bandanadham on May 26, 2009 1:04 PM

  • How to create dynamic data tables with ADF 10g

    Hi,
    Can anyone provide sample code for creating dynamic data table in adf where column & row will be added dynamically according to the data coming from the Array List of data.
    I appreciate your help here.

    I think you've posted to the wrong forum. This one is for WebLogic Portal questions.
    Try the ADF/DVT forum:
    http://myforums.oracle.com/jive3/forum.jspa?forumID=1565

  • How to update or populate table in SQL server from PL/SQL

    Hello - I am starting in the fascinating world of PL/SQL. One of the first task I've been assigned is to rewrite a code (basically I was thinking of creating a package with proc included) on PL/SQL that updates and/or populates tables in MS SQL Server. How should I do this? Is it doable? I guess it is. How can I call tables from others databases from PL/SQL? How to establish the conecction? where? It should be included in the package?
    Any help will be appreciated
    Thanks,
    CC

    See PL\SQL and SQL Server

  • How do you compare Oracle 10G with SQL Server 2005?

    exept for performance and pricing...
    We haven't decide to upgrade SQL Server 2000 to SQL Server 2005 or buy more license for Oracle 10G...
    Any comments are welcome!

    OK I only came here because of APC's referral down the piece (I was curious where all the hits came from - cheers Andrew). Comments embedded anyway
    Thanks Gaff!
    * Staff Experience with product - how flexible is
    your staff?
    --Staff need to learn sth. new...:)That's a fair motivation if recruitment and retention of staff is an issue - if you want reliability giving business systems to people who don't know the tech is a rather foolish move.
    * Current product use Corporation/group - if you have
    15 SQL Server boxes and no Oracle, what is the
    impetus for change? Same if you have 15 Oracle boxes
    and no SQL Server ones.
    --80% SQL server and 20% Oracle. We are thinking to
    balance to 50%-50%.I'm curious as to the reasoning behind this? I don't really see what the benefit is.
    * Features - Do you want/need text handling
    capabilities? Data mining? Storage of non-text
    records? XML?
    --I think both of DB system can do these.They can
    * Scalability - Is one Windows box going to meet your
    needs or do you need to scale (now or eventually) to
    multiple boxes of multiple CPUs?
    --This is really a benefit feature of Oracle better
    than SQL Server.SQLServer scales - it just scales in a different way (federated databases vs RAC).
    Thank u for ur US$.02Are you evaluating the platform for an in-house development or a database neutral application - if the latter I'd be sorely tempted to find out what the development platform is or read the docs for clues. For example we are looking at a product that supports SQLServer,MSDE and Oracle. In the FAQ "how do I choose between SQLServer and MSDE?", if we do implement it will be on an MS platform.
    I consider this probably the most crucial factor since SQLServer and Oracle have different architectural features they tend to generate different development approaches - porting one to the other nearly always hurts the new platform. Plus if I need support I'd be hoping that I got a bug fix from a developer and not from a developer whose fix was then ported.
    The same applies to in-house dev obviously, but there at least you can hire people with the right skillset for the app development.
    Cheers
    Niall Litchfield
    Oracle DBA
    http://www.niall.litchfield.dial.pipex.com

  • HOW TO CREATE WINDOWS AUTHENTICATION USER IN SQL SERVER AFTER INSTALLING SQL SERVER 2008

    I had an error while executing asp.net appcation from IIS as follows
    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
    Description:
    An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
    [SqlException (0x80131904): Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.]
    Can the above problem be solved by CREATING WINDOWS AUTHENTICATION LOGIN FOR
    'IIS APPPOOL\ASP.NET v4.0'  ?
    If yes, how to create the login?
    If no,what is the best possible solution?
    Please reply as soon as possible as i am unable to run my project which I had done in my lab,in my home system.

    Hi Praveen,
    To fix this issue, you need to change the Identity of your website's Application Pool to use the
    NetworkService account (or the less secure LocalSystem account).  By default, IIS7 seems to set the Application Pools Identity to 'ApplicationPoolIdentity' instead of NetworkService or LocalSystem.
    Here's a step-by-step guide for determining your websites Application Pool, then changing its Process Model Idenitty in IIS7:
    1.Open Internet Information Services (IIS) Manger.
    2.In the Connections sidebar, drill down into Default Web Site and click on your website.
    3.Now in the Actions sidebar (on right side), click on Advance Settings... In the popup box, under General you will see your Application Pool listed for your website (in my case the app pool is: ASP.NET V4.0).
    4.Click Cancel...  If you choose, you can change the Application Pool here, but for the sake of this example we just wanted to find out what the website's App Pool was.
    Then change the app pool's (Process Model) Identity to 'NetworkService', the steps are showed as below:
    1.Open Internet Information Services (IIS) Manger.
    2.In the Connections sidebar, click on Application Pools.
    3.Now right-click on theApplication Pool that your website is using (in this case my site is using the ASP.NET v4.0 application pool), and select Advanced Settings... from the menu.
    4.In the Advanced Settings pop-up box, locate the Process Model -> Identity section and click on the Application Pool Identity.
    5.In the Application Pool Identity pop-up box, change the Built-in account to NetworkService (or if you want LocalSystem), then click OK, and click OK again to save your Advanced Settings changes.
    Hope this helps.
    Best Regards,
    Peja
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

Maybe you are looking for

  • A recent convert from PC: External Hard drive, iTunes library, and NTFS

    So I recently picked up an iBook and am using it in addition to my Toshiba laptop. My entire collection of mp3's is about 13,000 songs, occupies over 40 gig and is stored on an external hard drive. All tags are complete and accurate (That was a long,

  • PHOTOSHOP ELEMENTS 8 VS WINDOWS 8.1

    Bonjour, J'utilisais Photoshop Élements 8 sur la version 7 de Windows. Récemment, j'ai fait l'Acquisition d'un ordinateur MAC partitionné entre MAC OS et Windows 8.1. Depuis l'acquisition de Windows 8.1, Élements 8 est pratiquement inutilisable. La t

  • Need to have the mail trigger to manager whenever bank details are changed

    Dear Experts, We got a  requirement on  changing the Infotype .Whenever the employees Bank details  Infotype are changed,a mail has to be triggered to the HR Manager. What should we do for this requirement. Please advice. Thanks and Regards, Sairam.

  • Restoring back up from TM! Need help!

    I just bougth a new hard disc, and i am trying to restore my system from Time Machine, the problem is I only have the setup disc for Mac OS X 10.4.10 Tiger, I can't find my Leopard upgrade. Now I can't figure out how to restore it from my back up. An

  • Can AirPort Express extend the range of my Dlink

    Hi, Wonder if Airport Express would extend the wifi range of my Dlink wifi gateway and would actually work properly with it? Apreciate help ASAP! Dlink router: DVG-N5402SP Wifi Gateway ( Provided by ISP )