Skip to main content
Inspiring
July 15, 2009
Question

Using Temporary Table with DW Recordset Behavior

  • July 15, 2009
  • 1 reply
  • 676 views

Is it possible to use SQL Temporary Tables when creating a recordset using the DW behavior? Any ideas would be greatly appreciated.

I have the following that works fine when entered used as straight SQL but It's not working when I enter it in the Advanced settings of the DW Recordset behavior:

CREATE TEMPORARY TABLE TEMP_LOGIN_COUNT AS (
SELECT
   user.USER_NAME,
   user.FIRST_NAME,
   user.LAST_NAME,
   user.EMAIL_ADDRESS,
   sch.SCHOOL_ID,
   sch.SCHOOL_ABBREV,
   COUNT( history.DATETIME ) AS LOGIN_COUNT
FROM C_USER AS user
LEFT OUTER JOIN C_USER_LOGIN_HISTORY AS history
   ON user.USER_NAME = history.USER_NAME
LEFT JOIN C_SCHOOL AS sch
   ON user.SCHOOL_ID = sch.SCHOOL_ID
GROUP BY user.USER_NAME
);

SELECT
loginCount.USER_NAME,
loginCount.FIRST_NAME,
loginCount.LAST_NAME,
loginCount.EMAIL,
loginCount.SCHOOL_ID,
loginCount.SCHOOL_ABBREV,
loginCount.LOGIN_COUNT
FROM
TEMP_LOGIN_COUNT AS loginCount
LEFT JOIN USER_USER_TYPE AS type
ON loginCount.USER_NAME = type.USER_NAME
GROUP BY loginCount.USER_NAME
HAVING
SUM( type.USER_TYPE_ID ) =3
AND
COUNT( type.USER_TYPE_ID ) =1
ORDER BY loginCount.LAST_NAME, loginCount.FIRST_NAME;

This topic has been closed for replies.

1 reply

Participating Frequently
July 15, 2009

I honestly do not know if the DW behaviors support DDL commands. But have you thought about using a derived table instead of a temp?

MichaelSAuthor
Inspiring
July 15, 2009

I have thought about using a Derived table but from everything I've read it's buggy in MySQL 4.1 and can cause MySQL to crash and restart while using up 100% of the CPU. We tried it and the query was taking so long we ditched the idea.

Thanks for your reply though.

Participating Frequently
July 15, 2009

What about using a view then?

Or, just create the temp table outside the RS behavior code?

Or, use a stored procedure?