Carl
Carl

Reputation: 36

Can Sequel Create And Query Temp Tables

I am new to Sequel, but have a lot of background in SQL. Getting frustrated with what I would call basic query functions not working. I am hoping it's a matter of just getting syntax correct. I would like to create a temporary table, insert values into that table, then run a query against it. In SQL I'd run this-

CREATE TABLE #TMP (CHRGCD VARCHAR)
INSERT INTO #TMP SELECT DISTINCT(CHRGCD) FROM PACPTCD WHERE CCTRMDT = '9999-01-01'

SELECT CHRGCD FROM PACPTCD 
WHERE CHRGCD NOT IN (SELECT CHRGCD FROM #TMP)

Can I do this all from Sequel or am I going to have to create a real table, run a separate script to populate it, the run the last part of the query?

The data in the table PACPTCD can have multiple entries for CHRGCD but the CCTRMDT can vary. I'm trying to find all instances where CHRGCD doesn't have a value of 9999-01-01. Seems to be the easiest way to do it. Open to suggestions on other ways to get the data.

Upvotes: 0

Views: 544

Answers (1)

Carl
Carl

Reputation: 36

Thanks user007. I ended up changing the query.

 SELECT CHRGCD FROM PACPTCD
 WHERE CHRGCD NOT IN (SELECT DISTINCT(CHRGC) FROM PACPTCD WHERE CCTRMDT='9999-01-01')

Dozen ways to do it. This one is the easiest. Even easier than my original.

Upvotes: 0

Related Questions