Create table for the results of a SQL statement
Is there a way to create a table for the results of a SQL statement ?
Example: Consider the below query and results.
Select ID,Name,DOB,Gender from EMS.EMS
RESULT
| ID | NAME | DOB | Gender |
|---|---|---|---|
| 1 | Wijnschenk,Greta N. | 03/09/2009 | F |
| 2 | Klausner,Barbara L. | 03/08/2014 | M |
| 3 | Eastman,Liza X. | 03/11/2000 | F |
| 4 | O'Brien,Barb K. | 03/07/2016 | M |
| 5 | Anderson,Nataliya Y. | 03/14/1991 | F |
| 6 | Long,Debby Z. | 03/12/1999 | F |
| 7 | Rogers,Susan W. | 03/12/1997 | F |
| 8 | Ott,Lola J. | 03/09/2009 | F |
| 9 | Yu,Alice S. | 03/14/1990 | M |
| 10 | Wilson,Debby I. | 03/12/1998 | M |
So, for the above results I want a table named EMS.BASIC which have properties NAME,DOB and Gender with the resulted values.
Thanks in advance.
Comments
2 steps:
- create the new table EMS.BASIC
- INSERT INTO EMS.BASIC (Name,DOB,Gender) Select Name,DOB,Gender from EMS.EMS
thanks
This works, exactly I wanted !! Thanks a lot to everyone.
Do you mind sharing what are you trying to accomplish that you need a dynamic table creating mechanism?
Apparently deprecated in Iris 2025, but the documentation suggests its been superseded by something of the same name in $SYSTEM.SQL.Schema.QueryToTable -which doesn't exist on the relevant documentation page! See: https://docs.intersystems.com/iris20252/csp/documatic/%25CSP.Documatic…
Try CREATE TABLE AS SELECT command
Its easy to use. See: CREATE TABLE AS SELECT (SQL) | InterSystems SQL Reference | InterSystems IRIS Data Platform 2025.2