?
Solved

Declare a Temporary Table

Posted on 2011-09-26
5
Medium Priority
?
188 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 2000 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

719 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