Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sum on Union
Message
From
04/02/2013 10:47:39
 
 
To
04/02/2013 10:26:42
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01565061
Message ID:
01565063
Views:
44
I have found this, but this requires an additional step:
UPDATE Menu SET Count=Temp2.RecordCount FROM Menu JOIN
(SELECT Menu2.Numero,SUM(RecordCount) As RecordCount FROM
(SELECT Menu.Numero,COUNT(*) AS RecordCount
 FROM Menu
 INNER JOIN MenuEntity ON Menu.Numero=MenuEntity.NoMenu
 INNER JOIN MenuPrivilege ON Menu.Numero=MenuPrivilege.NoMenu
 INNER JOIN MenuRole ON Menu.Numero=MenuRole.NoMenu
 INNER JOIN Member ON MenuEntity.NoEntity=Member.NoEntity AND
  MenuPrivilege.NoType=Member.NoType AND MenuRole.NoRole=Member.NoRole
 WHERE Menu.Numero NOT IN (SELECT Menu.Numero FROM MenuPrivilegeExceptionCase
 INNER JOIN Menu ON MenuPrivilegeExceptionCase.NoMenu=Menu.Numero
 WHERE MenuPrivilegeExceptionCase.NoMember=Member.Numero)
 GROUP BY Menu.Numero
UNION
 SELECT Menu.Numero,COUNT(*) AS RecordCount
 FROM Menu
 INNER JOIN MenuPrivilegeExceptionCase ON Menu.Numero=MenuPrivilegeExceptionCase.NoMenu AND
  MenuPrivilegeExceptionCase.Enabled=1
 INNER JOIN MenuEntity ON Menu.Numero=MenuEntity.NoMenu
 INNER JOIN Member ON MenuEntity.NoEntity=Member.NoEntity
 WHERE MenuPrivilegeExceptionCase.NoMember=Member.Numero
 GROUP BY Menu.Numero) Temp
INNER JOIN Menu AS Menu2 ON Temp.Numero=Menu2.Numero
GROUP BY Menu2.Numero) AS Temp2 ON Temp2.Numero=Menu.Numero
If there is a way to shortening that out, you may let me know.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform