Solved

Two databases one view

Posted on 2013-12-05
11
236 Views
Last Modified: 2013-12-27
Ok, I have a history database and a live database.  I want to combine the two for a report.  So should I make a view of the live company or the history company?  

Right now I have a view created from the live company and when I run the report, it is not giving me the order dates from the live company, just the history company.  Do I have the view setup wrong or are my links setup wrong in database expert?

New to making views, so need some help.
0
Comment
Question by:TomBalla
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 11

Expert Comment

by:Simone B
ID: 39699089
Can you post the code for your view?
0
 

Accepted Solution

by:
TomBalla earned 0 total points
ID: 39699189
The view has 3 tables.


SELECT     dbo.InvMaster.StockCode, dbo.SorDetail.SalesOrder, dbo.SorMaster.SalesOrder AS Expr1, dbo.InvMaster.ConvFactOthUom, dbo.SorDetail.MStockCode,
                      dbo.SorDetail.MStockDes, dbo.SorDetail.MOrderQty, dbo.SorDetail.MOrderUom, dbo.SorDetail.MPrice, dbo.SorDetail.MDiscValue, dbo.SorDetail.MConvFactAlloc,
                      dbo.SorMaster.OrderStatus, dbo.SorMaster.OrderDate
FROM         dbo.InvMaster INNER JOIN
                      dbo.SorDetail ON dbo.InvMaster.StockCode = dbo.SorDetail.MStockCode INNER JOIN
                      dbo.SorMaster ON dbo.SorDetail.SalesOrder = dbo.SorMaster.SalesOrder
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39699384
Because you haven't specified a database anywhere in your query, all of your data will be coming from the database where the view resides. So if the data in your report is showing History only, then I would expect to find the view in the History database.

If the two databases are on the same SQL instance, it doesn't matter which one holds the view, but you do have to tell the view where to get the data. Also, it's good practice to use aliases for your tables.

I don't know your data, so I can't tell what you expect or which database you want to use for each table. But the example below shows how you can get the StockCode and a SalesOrder from Live, and another SalesOrder from History.

SELECT L_IM.StockCode, H_SD.SalesOrder, L_SM.SalesOrder AS Expr1
FROM Live.dbo.InvMaster L_IM
INNER JOIN History.dbo.SorDetail H_SD ON L_IM.StockCode = H_SD.MStockCode
INNER JOIN Live.dbo.SorMaster L_SM ON H_SD.SalesOrder = L_SM.SalesOrder

The above is obviously just an example, and assumes you can link the keys correctly between History and Live. I would need more information as to how you want to join the tables to get a more accurate query.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:TomBalla
ID: 39699406
The code I wrote above is all Live company (company S).  This code is the view I made in sql management studio.  

In crystal reports I made a report based off the history company (company H) and just added the view from the live company (S) through an odbc connection and linked them together.  

Am I doing this correct?
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39699450
Hmmm... I was looking at this from the SQL perspective. It's been a while since I've used Crystal, but I recall you should be able to see the query behind the report. Once you've run the report, you will need to "Show SQL Query." That will give you a good idea of where the data is coming from. I believe it's on the Database menu.
0
 

Author Comment

by:TomBalla
ID: 39699500
here is sql query from crystal reports.



 SELECT "SorDetail"."MStockCode", "SorDetail"."MOrderQty", "SorDetail"."MStockUnitMass", "SorDetail"."MPrice", "SorDetail"."MWarehouse", "SorDetail"."SalesOrder", "SorDetail"."MOrderUom", "SorDetail"."MConvFactAlloc", "SorMaster"."OrderDate", "InvMaster"."ConvFactOthUom", "SorMaster"."OrderStatus", "SorDetail"."MDiscValue", "SorMaster"."Customer"
 FROM   ("SysproCompanyH"."dbo"."SorDetail" "SorDetail" INNER JOIN "SysproCompanyH"."dbo"."SorMaster" "SorMaster" ON "SorDetail"."SalesOrder"="SorMaster"."SalesOrder") INNER JOIN "SysproCompanyH"."dbo"."InvMaster" "InvMaster" ON "SorDetail"."MStockCode"="InvMaster"."StockCode"
 WHERE  "SorMaster"."OrderStatus"='9' AND ("SorMaster"."OrderDate">={ts '2011-12-14 00:00:00'} AND "SorMaster"."OrderDate"<{ts '2011-12-21 00:00:01'}) AND ("SorDetail"."MWarehouse"='38' OR "SorDetail"."MWarehouse"='39' OR "SorDetail"."MWarehouse"='40' OR "SorDetail"."MWarehouse"='41' OR "SorDetail"."MWarehouse"='42' OR "SorDetail"."MWarehouse"='43' OR "SorDetail"."MWarehouse"='44' OR "SorDetail"."MWarehouse"='45' OR "SorDetail"."MWarehouse"='46' OR "SorDetail"."MWarehouse"='47' OR "SorDetail"."MWarehouse"='48' OR "SorDetail"."MWarehouse"='49')
0
 
LVL 18

Expert Comment

by:vasto
ID: 39699546
TomBalla , mixing tables / views from different databases will slow the report. Try to implement the code provided by Buttercup1. If you don't want to start your report from scratch you change the view you create and to use just the view in your report.
0
 

Author Comment

by:TomBalla
ID: 39699601
So nevermind the View, just change the sql query to have both databases?
0
 
LVL 18

Expert Comment

by:vasto
ID: 39699609
If you are using tables you will be not able to change the query directly. In order to implement the solution proposed by Buttercup1 you need to create a command and redevelop your report from scratch. As a workaround you can update just the view and use it directly in your report
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39700175
Another way to handle this in Crystal is to use the live database for the main report and include a subreport that shows the related data from the history table.

mlmcc
0
 

Author Closing Comment

by:TomBalla
ID: 39741478
need to add a union
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
coldfusion upload spreadsheet into the databse 2 41
SQL LINE CONTINUATION ISSUE 12 31
SQL Server tables join on parse list 6 21
insert wont work in SQL 14 18
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

813 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

17 Experts available now in Live!

Get 1:1 Help Now