?
Solved

creating view with union all

Posted on 2012-08-24
5
Medium Priority
?
752 Views
Last Modified: 2012-08-24
I have a query that uses union all that I am trying to turn into a view. But I am getting errors. This is the query.  ProductionCosts.txt Usually creating a view from a query is pretty simple. I tried it several ways without any luck. I triedCOO-TotalProductionCost-view1.txt and I tried it without the field names listed . What do I need to do to make it work?
0
Comment
Question by:qbjgqbjg
  • 2
  • 2
5 Comments
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 1000 total points
ID: 38330777
Howdy....

I don't see anything in the query that would prevent it from being used as the core query in a view.

What error(s) are you getting?

Also, about how many rows do you expect this to return?


Kent
0
 
LVL 8

Assisted Solution

by:stalhw
stalhw earned 1000 total points
ID: 38330981
I think your Create view syntax maybe wrong...
I dont think you need to define the fields...

did you try just
create view [dbo].[COO_TotalProductionCost_vw]
as

SELECT
    PAPROJNUMBER
    ,PACONTNUMBER
    ,WOStatus
    ,WOType
    ,ConstEndDt
    ,End_month  = case when year(ConstEndDt) <> 1900 then month(ConstEndDt)end
    ,End_year  = case when year(ConstEndDt) <> 1900 then  year(ConstEndDt)end
    ,CapitalizationMethod
    ,CapitalizationLTD
*etc*

Open in new window

0
 

Author Comment

by:qbjgqbjg
ID: 38331098
I think I figured it out. I was running the query in our live environment. It worked fine. But I was trying to create the view in a test environment. So, I think there is something different in test.
0
 

Author Closing Comment

by:qbjgqbjg
ID: 38331100
Thanks for your help.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 38331190
One final comment...

This is a fairly complex view.  It reads from several tables and has the potential to generate a lot of rows.

Find out how many rows this returns.

  SELECT count(*) FROM myview;

If it's a large number, you'll be well served to avoid using the view when you need to filter the results.  You can get better performance by applying the filter directly to the subquery than you can by applying it to the results of the view.


Kent
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline

839 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