Solved

Declare a Temporary Table

Posted on 2011-09-26
5
186 Views
Last Modified: 2012-08-14
Hello,

I'm having a problem declaring a temporary table in a stored procedure.

The word TABLE is underlined in RED with a syntax error.
Its the first time I've done this so I dont know whats wrong.

Any ideas?
Thanks
Dan
-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE PROCEDURE `db`.`selectlatestrates` ()
BEGIN
    DECLARE latestwholesaledate DATE;
    DECLARE latestretaildate DATE;
    
    DECLARE resultstable TABLE(
        [fAreaName] VARCHAR(200),
        [fCode] VARCHAR(20),
        [fWholesalePeak] DECIMAL(10,3),
        [fRetailPeak] DECIMAL(10,3),
        [fWholesaleOffPeak] DECIMAL(10,3),
        [fRetailOffPeak] DECIMAL(10,3),
        [fWholesaleConnectionFee] DECIMAL(10,3),
        [fRetailConnectionFee] DECIMAL(10,3),
        [fWholesaleMinimumFee] DECIMAL(10,3),
        [fRetailMinimumFee] DECIMAL(10,3)
    );
    
END$$

Open in new window

0
Comment
Question by:DanJourno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 36598236
0
 
LVL 3

Expert Comment

by:anjos
ID: 36598303
Here is an easy but pretty clear example:

        DECLARE  @TABLE TABLE(A int, B int, C varchar(50), D int, E datetime, F int)

      INSERT INTO @TABLE(A, B, C, D, F)
      SELECT      CUA_A AS A,
                  B,
                  C,
                  SUM(D) AS D,
                  COUNT(B) AS F
      FROM      CUA_CustomerArticle CUA
                  JOIN ART_Article
                        ON      CUA_B = B
      WHERE      CUA.CUA_A = @A
      Group by B, C, CUA_A
            
      UPDATE      @TABLE
            SET      E = CUAs.E
      FROM      CUA_CustomerArticle AS CUAs
      WHERE      CUAs.CUA_A = A
      
      SELECT      *
      FROM      @TABLE
      Order by C
0
 
LVL 5

Author Comment

by:DanJourno
ID: 36598331
anjos,

That doesnt seem the work. The same problem as I already reported.
0
 
LVL 3

Expert Comment

by:anjos
ID: 36598363
and if you use 'CREATE TEMPORARY TABLE' ?
0
 
LVL 5

Author Closing Comment

by:DanJourno
ID: 36598400
Thanks. This was perfect.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question