creating view with union all

Posted on 2012-08-24
Medium Priority
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?
Question by:qbjgqbjg
  • 2
  • 2
LVL 46

Accepted Solution

Kent Olsen earned 1000 total points
ID: 38330777

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?


Assisted Solution

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]

    ,End_month  = case when year(ConstEndDt) <> 1900 then month(ConstEndDt)end
    ,End_year  = case when year(ConstEndDt) <> 1900 then  year(ConstEndDt)end

Open in new window


Author Comment

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.

Author Closing Comment

ID: 38331100
Thanks for your help.
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.


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