Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
djamit
Starting Member
17 Posts |
Posted - 2013-08-02 : 11:58:54
|
Hi,I am using a query to join to tables, but i want to put the query results into a new table. How should I do this?This is the query:Select Query.PAT_NAME,Query.IDA,Query.MD_INITIALS,Query.LOCATION,Query.App_DtTM,Query.Sch_Id,vw_PatBro_Admissions.Birth_DtTm,vw_PatBro_Admissions.IDA,vw_PatBro_Admissions.Gender,vw_PatBro_Admissions.MDNamefrom Query inner join vw_PatBro_Admissionson Query.IDA=vw_PatBro_Admissions.IDA |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-02 : 12:22:00
|
you can do something like this:[CODE]-- CREATE A TABLE USING THE CORRECT DATA TYPESCREATE TABLE dbo.Temp101 ( PAT_NAME VARCHAR(20), IDA VARCHAR(20), MD_INITIALS VARCHAR(20), LOCATION VARCHAR(20), App_DtTM VARCHAR(20), Sch_Id VARCHAR(20), Birth_DtTm DATE, IDA2 VARCHAR(20), Gender VARCHAR(2), MDName VARCHAR(20));INSERT INTO dbo.Temp101(Select Query.PAT_NAME, Query.IDA, Query.MD_INITIALS, Query.LOCATION, Query.App_DtTM, Query.Sch_Id, vw_PatBro_Admissions.Birth_DtTm, vw_PatBro_Admissions.IDA, vw_PatBro_Admissions.Gender, vw_PatBro_Admissions.MDNamefrom Query inner join vw_PatBro_Admissions ON Query.IDA = vw_PatBro_Admissions.IDA)-- DROP THE TABLE WHEN YOU ARE DONEDROP TABLE dbo.Temp101 [/CODE] |
|
|
djamit
Starting Member
17 Posts |
Posted - 2013-08-02 : 14:01:13
|
THANKS |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-08-02 : 23:46:52
|
the easiest way to create a table using query on the fly would be using SELECT... INTO syntax.Query.PAT_NAME,Query.IDA,Query.MD_INITIALS,Query.LOCATION,Query.App_DtTM,Query.Sch_Id,vw_PatBro_Admissions.Birth_DtTm,vw_PatBro_Admissions.IDA,vw_PatBro_Admissions.Gender,vw_PatBro_Admissions.MDNameINTO NewTableNamefrom Query inner join vw_PatBro_Admissionson Query.IDA=vw_PatBro_Admissions.IDA ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|