troubleshooting Question

Query won't work as a View

Avatar of Travidia
Travidia asked on
Microsoft SQL Server 2005
5 Comments1 Solution195 ViewsLast Modified:
I have this query and I want to set it as a view.  

WITH CMS(Username, Workflow_action, type1, type2, ROPID, AdID, SubRegionID, date_created, ShiftDate) AS (SELECT DISTINCT
username, workflow_action, type1, type2, ROPID, AdID, SubRegionID, date_created, ShiftDate
FROM     dbo.view_FD_QCers
WHERE  (SubRegionID = 0) AND (ShiftDate BETWEEN GETDATE() - 3 AND GETDATE())),

FD(username, AdID, SubRegionID, action_time, ShiftDate) AS
(SELECT DISTINCT username, AdID, SubRegionID, action_time, ShiftDate
FROM     dbo.view_BPOFDSub_QC AS view_FD_QCers_1
WHERE  (SubRegionID <> 0) AND (ShiftDate BETWEEN GETDATE() - 3 AND GETDATE())
Union
SELECT DISTINCT username, AdID, SubRegionID, action_time, ShiftDate
FROM     dbo.view_Chico_FDSub_QC AS view_FD_QCers_1
WHERE  (SubRegionID <> 0) AND ShiftDate BETWEEN GETDATE() - 3 AND GETDATE()
),

FDFinal(UserName, AdID, SubRegionID, ShiftDate) AS
(SELECT DISTINCT Username, AdID, SubRegionID, ShiftDate
FROM     FD AS FD_1
WHERE  (ShiftDate = CAST(CONVERT(varchar(12), GETDATE() - 1, 101) AS datetime))),

CMSFinal(UserName, AdID, SubRegionID, ShiftDate) AS
(SELECT DISTINCT Username, AdID, SubRegionID, ShiftDate
FROM     CMS AS CMS_1
WHERE  (ShiftDate = CAST(CONVERT(varchar(12), GETDATE() - 1, 101) AS datetime)))

SELECT  ShiftDate, UserName, COUNT(AdID) AS AdCount, 0 AS SubCount
FROM     CMSFinal AS CMSFinal_1
GROUP BY ShiftDate, UserName
UNION
SELECT  ShiftDate, UserName, 0 AS AdCount, COUNT(SubRegionID) AS SubCount
FROM     FDFinal AS FDFinal_1
GROUP BY ShiftDate, UserName

When I put it into the query and save it, I get error 'Invalid Field Name FD'
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros