Solved

Assistance in Creating a View from 2 unrelated tables

Posted on 2010-11-17
4
311 Views
Last Modified: 2012-05-10
Hi Experts,

Create View VWCurrentGgl

as


Select GlYear, GlPeriod,'' as AccountType, '' as ExpenseType, Company, '' as GlCode, '' as Description,0 as PeriodMovement
from dbo.GenControl

Union all

Select Convert(Int,'') as GlYear, Convert(Int,'') as GlPeriod ,AccountType, ExpenseType, Company,GlCode, Description, CurrentBalance - PrevPerEndBal  As PeriodMovement
from dbo.GenMaster

The Results are the screen shot attached...

How can i get the GlYear and GlPeriod to populate all the way down as opposed to the zero's (if I need to change my thinking from a view to something else please let me know and assist)
View.JPG
0
Comment
Question by:Mikeyman_01
  • 2
4 Comments
 
LVL 17

Expert Comment

by:OriNetworks
Comment Utility
Select GlYear, GlPeriod,'' as AccountType, '' as ExpenseType, Company, '' as GlCode, '' as Description,0 as PeriodMovement
from dbo.GenControl

Union all

Select Convert(Int,'2010') as GlYear, Convert(Int,'2') as GlPeriod ,AccountType, ExpenseType, Company,GlCode, Description, CurrentBalance - PrevPerEndBal  As PeriodMovement
from dbo.GenMaster

Open in new window

0
 
LVL 17

Expert Comment

by:OriNetworks
Comment Utility
i'm not sure what the point of the first record is if it has no relation. There has to be some calculation or reasoning for knowing what year and period to display. Maybe a stored procedure would be better?

@Year int
@Period int

Select @Year as GlYear, @Period as GlPeriod,AccountType, ExpenseType, Company,GlCode, Description, CurrentBalance - PrevPerEndBal  As PeriodMovement
from dbo.GenMaster

0
 
LVL 1

Accepted Solution

by:
VBisMe earned 500 total points
Comment Utility
Basing my results on that the GenControl table appears to have a single record, you should join the 2 tables rather than unioning them:

Select gc.GlYear, gc.GlPeriod, gm.AccountType, gm.ExpenseType, gm.Company, gm.GlCode, gm.Description, gm.CurrentBalance - gm.PrevPerEndBal  As PeriodMovement
from dbo.GenMaster gm
INNER JOIN dbo.GenControl gc ON 1 = 1  --Dummy join

OR

Select (SELECT glYear FROM dbo.GenControl) AS GlYear,
       (SELECT GlPeriod FROM dbo.GenControl) as GlPeriod,
       AccountType, ExpenseType, Company, GlCode, Description, CurrentBalance - PrevPerEndBal  As PeriodMovement
from dbo.GenMaster
0
 

Author Closing Comment

by:Mikeyman_01
Comment Utility
Brilliant answer.. Thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now