Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Querying views

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2004-08-09 : 11:11:32
Afternoon!

I have to query 4 views in order to create a final report which is to be run on a monthly basis. Rather than having to run the 4 queries before the final one to ensure they contain uptodate data, I want to populate the 4 views in the final query. I know there is a way to do this as I stumbled across it the other day. However, I cannot locate this source and so was wondering if anyone can tell me how it is done??? Here is the code for my final query (created in SQL Query Analyser):

USE CPW_EBillingReporting

SET NOCOUNT ON

DECLARE @Date SMALLDATETIME
SET @Date = GETDATE()

SELECT dbo.Total_Bounces.Cycle_Date, dbo.Total_Bounces.Cycle_Code, dbo.Total_Bounces.Total_Bounces,
dbo.Soft_Bounces.Soft_Bounces, dbo.Hard_Bounces.Hard_Bounces, dbo.Unknown_Bounces.Unknown_Bounces

FROM dbo.Hard_Bounces INNER JOIN dbo.Soft_Bounces ON dbo.Hard_Bounces.Cycle_Instance_Id = dbo.Soft_Bounces.Cycle_Instance_Id
INNER JOIN dbo.Total_Bounces ON dbo.Soft_Bounces.Cycle_Instance_Id = dbo.Total_Bounces.Cycle_Instance_Id
INNER JOIN dbo.Unknown_Bounces ON dbo.Unknown_Bounces.Cycle_Instance_Id = dbo.Total_Bounces.Cycle_Instance_Id

WHERE dbo.Total_Bounces.Cycle_Date > DATEADD(MM,-1,@Date)AND dbo.Total_Bounces.Cycle_Date < GETDATE()

GROUP BY dbo.Total_Bounces.Cycle_Code, dbo.Total_Bounces.Cycle_Date, dbo.Total_Bounces.Total_Bounces,
dbo.Soft_Bounces.Soft_Bounces, dbo.Hard_Bounces.Hard_Bounces, dbo.Unknown_Bounces.Unknown_Bounces

Thanks in advance

Hearty head pats
   

- Advertisement -