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
Solved

Creating a table from a view

Posted on 2008-06-21
5
230 Views
Last Modified: 2010-04-21
Hi Experts:
I've created a view in SQL2000.  This view is created using 2 tables and another view.  Now I need to create a table from the results of this view so that I can export the results in txt comma deliminated format.  This is the code I have so far:

SELECT qry_Project_Request_HE_001.*, DATEDIFF(M,(SUBSTRING([AADOB],5,2) + '/' + Right([AADOB],2) + '/' + Left([AADOB],4)),
       (SUBSTRING([BEG_DATE_SERV],5,2) + '/' + Right([BEG_DATE_SERV],2) + '/' + Left([BEG_DATE_SERV],4)))/365.25 AS Age_DOS,
        ABPLAN AS Aid_Code, ABIPA AS IPA, 'County' = CASE
           WHEN ABGRUP like 'Riv%' THEN 33
           WHEN ABGRUP <> 'Riv%' THEN 36 END, abgrup, AASEX AS Gender, qry_Project_Request_HE_001.Beg_Date_Serv
FROM IEHPSQL2.Diam_725.diamond.JMEMBRM0_DAT JMEMBRM0_DAT_1 INNER JOIN
                      IEHPSQL2.Diam_725.diamond.JMELIGM0_DAT JMELIGM0_DAT_1 ON JMEMBRM0_DAT_1.AASUBNO = JMELIGM0_DAT_1.ABSUBNO AND
                      JMEMBRM0_DAT_1.AAPERSNO = JMELIGM0_DAT_1.ABPERSNO INNER JOIN
                      dbo.Qry_Project_Request_HE_001 ON
                      JMEMBRM0_DAT_1.AASUBNO COLLATE SQL_Latin1_General_CP1_CI_AS = dbo.Qry_Project_Request_HE_001.SubID AND JMEMBRM0_DAT_1.AAPERSNO COLLATE SQL_Latin1_General_CP1_CI_AS = dbo.Qry_Project_Request_HE_001.Pers_no
WHERE (qry_Project_Request_HE_001.Beg_Date_Serv)>=[ABEFFDT] And (qry_Project_Request_HE_001.Beg_Date_Serv)<=[ABTERMDT] OR
      (qry_Project_Request_HE_001.Beg_Date_Serv)>=[ABEFFDT] And (qry_Project_Request_HE_001.Beg_Date_Serv)<'0'

I can't figure out how to create the new table without having to create it manually for all the fields.

Thanks in advance.
0
Comment
Question by:IEHP1
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21838349
here we go:
SELECT * 
  INTO your_new_table
 FROM your_view

Open in new window

0
 

Author Comment

by:IEHP1
ID: 21838394
Hi angellll and thanks for the response.  

My issue is I created the view in SQL analyzer and can't save it as a view because of the case statement.  And will your solution above create a brand new table?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21838402
>My issue is I created the view in SQL analyzer and can't save it as a view because of the case statement.  
you are using the view/query designer?
forget that "tool", it indeed cannot handle the CASE statement, run the CREATE VIEW statement as a normal query.

note: in 95% of the view I create on my databases there is at least 1 case statement, hence the query designer is useless to me.
0
 

Author Closing Comment

by:IEHP1
ID: 31469456
It worked.  Thank you VERY much
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21838420
you are welcome
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

840 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