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
 General SQL Server Forums
 New to SQL Server Programming
 OVER SQL constructor not supported

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-04-12 : 07:57:06
Hi,

I have this query which works OK, but when I try to create a view I receive a Query Definitions Differ - The OVER SQL construct or statement is not supported. The query cannot be represented graphically in the Diagram and Criteria Pane.

SELECT cc.Surname
,cc.ContactCode as [Contact Code]
,ge.ObsResearchOther as [Other Observational Research]
,gx.InterResearchOther as [Other Interventional Research]
,gz.DiseaseAreaOther as [Other Disease Area]
,ga.InterestGroupADesc as [Area of Interest]
,gb.InterestGroupBListADesc as [Observational Research]
,gc.InterestGroupBListBDesc as [Interventional Research]
,gd.InterestGroupBListCDesc as [Disease Area]

FROM dbo.aspnet_cprdContacts AS cc

LEFT OUTER JOIN
(
SELECT ai .ContactCode
, iga.InterestGroupADesc
, ROW_NUMBER()
OVER( PARTITION BY ai.ContactCode
ORDER BY iga.InterestGroupADesc
) AS rnum
FROM dbo.aspnet_AreaofInterest AS ai
INNER JOIN
dbo.aspnet_InterestGroupA AS iga
ON ai.InterestCode = iga.InterestGroupAID
) AS ga

FULL OUTER JOIN
(
SELECT ab.ContactCode
, igb.InterestGroupBListADesc
, ROW_NUMBER()
OVER( PARTITION BY ab.ContactCode
ORDER BY igb.InterestGroupBListADesc
) AS rnum
FROM dbo.aspnet_ObservationalResearch AS ab
INNER JOIN
dbo.aspnet_InterestGroupBListA AS igb
ON ab.ObsResearchCode = igb.InterestGroupBListAID
) AS gb
ON gb.ContactCode = ga.ContactCode
AND gb.rnum = ga.rnum

FULL OUTER JOIN
(
SELECT ax.ContactCode
, igx.InterResearchOther
, ROW_NUMBER()
OVER( PARTITION BY ax.ContactCode
ORDER BY igx.InterResearchOther
) AS rnum
FROM dbo.aspnet_InterResearchOther AS ax
INNER JOIN
dbo.aspnet_cprdContacts AS igx
ON ax.ContactCode = igx.ContactCode
) AS gx
ON gx.ContactCode = gb.ContactCode
AND gx.rnum = gb.rnum

FULL OUTER JOIN
(
SELECT az.ContactCode
, igz.DiseaseAreaOther
, ROW_NUMBER()
OVER( PARTITION BY az.ContactCode
ORDER BY igz.DiseaseAreaOther
) AS rnum
FROM dbo.aspnet_DiseaseAreaOther AS az
INNER JOIN
dbo.aspnet_cprdContacts AS igz
ON az.ContactCode = igz.ContactCode
) AS gz
ON gz.ContactCode = gx.ContactCode
AND gz.rnum = gx.rnum

FULL OUTER JOIN
(
SELECT ac .ContactCode
, igc.InterestGroupBListBDesc
, ROW_NUMBER()
OVER( PARTITION BY ac.ContactCode
ORDER BY igc.InterestGroupBListBDesc
) AS rnum
FROM dbo.aspnet_InterventionalResearch AS ac
INNER JOIN
dbo.aspnet_InterestGroupBListB AS igc
ON ac.IntResearchCode = igc.InterestGroupBListBID
) AS gc
ON gc.ContactCode = gb.ContactCode
AND gc.rnum = gb.rnum


FULL OUTER JOIN
(
SELECT ad.ContactCode
, igd.InterestGroupBListCDesc
, ROW_NUMBER()
OVER( PARTITION BY ad.ContactCode
ORDER BY igd.InterestGroupBListCDesc
) AS rnum
FROM dbo.aspnet_DiseaseArea AS ad
INNER JOIN
dbo.aspnet_InterestGroupBListC AS igd
ON ad.DiseaseAreaCode = igd.InterestGroupBListCID
) AS gd
ON gd.ContactCode = gc.ContactCode
AND gd.rnum = gc.rnum

FULL OUTER JOIN
(
SELECT ae.ContactCode
, ige.ObsResearchOther
, ROW_NUMBER()
OVER( PARTITION BY ae.ContactCode
ORDER BY ige.ObsResearchOther
) AS rnum
FROM dbo.aspnet_ObsResearchOther AS ae
INNER JOIN
dbo.aspnet_cprdContacts AS ige
ON ae.ContactCode = ige.ContactCode
) AS ge
ON ge.ContactCode = gd.ContactCode
AND ge.rnum = gd.rnum

ON cc.ContactCode = COALESCE(ge.ContactCode , gd.ContactCode)
where cc.Surname ='Mascrier'


any help please, thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-12 : 08:00:15
How did you try to create the view?
In SSMS it could work..

CREATE View_Name AS
SELECT ...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-04-12 : 08:54:03
ok managed to get it working now.. thanks but when I replace

where cc.Surname ='Mascrier'


with

order by cc.surname


I receive the error message;

The ORDER By Clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specidied.


Tried to formulate;

Select Top (100) cc.Surname....

It worked, however, missed other records. The table has over 1000 records and still populating.. Is there a way to make TOP (all records kind of) syntax

Any help please....

Thanks
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2012-04-12 : 09:17:13
Read the following paying attention to the word 'unordered'.

http://en.wikipedia.org/wiki/Relation_(database)
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-04-12 : 11:01:25
any help please. Thank you
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-04-12 : 11:07:09
Use SELECT TOP 100 PERCENT

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-04-12 : 11:17:17
Ok,

This did it!! Thanks

But why when I open view it doesn't order by surname?

Thanks

Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2012-04-13 : 08:22:14
If you read the link I posted, you will see that a derived relation variable (ie a VIEW) is an unordered set.

MS SQL only allows the use of ORDER BY in a VIEW in conjunction with TOP. This is to enable the correct rows to be returned; the order of those rows is not guaranteed.

The only way to guarantee the order of the rows is to use ORDER BY on the outermost query.

eg


SELECT *
FROM YourView
ORDER BY surname



Go to Top of Page
   

- Advertisement -