Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Enhancement actual select to update all rows
Message
De
03/01/2013 09:07:27
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Enhancement actual select to update all rows
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01561223
Message ID:
01561223
Vues:
74
I have a select like this which calculates a count for a specific record:
SELECT SUM(Temp.RecordCount) AS RecordCount
FROM (SELECT 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 DBUsers ON MenuEntity.NoEntity=DBUsers.NoEntity AND MenuPrivilege.NoType=DBUsers.NoType AND MenuRole.NoRole=DBUsers.NoRole
WHERE Menu.Numero=58 AND
Menu.Numero NOT IN (SELECT Menu.Numero FROM MenuPrivilegeExceptionCase
INNER JOIN Menu ON MenuPrivilegeExceptionCase.NoMenu=Menu.Numero
WHERE Menu.Numero=58 AND MenuPrivilegeExceptionCase.NoMember=DBUsers.AI)
UNION
SELECT 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 DBUsers ON MenuEntity.NoEntity=DBUsers.NoEntity
WHERE Menu.Numero=58 AND MenuPrivilegeExceptionCase.NoMember=DBUsers.AI) AS Temp
Now, I need to update this select to get rid of the specific Menu.Numero=58 and update all Menu.Count field. Thus, only one command will calculate the value of all rows in that table. I have done something like this before but not with such a complex SQL.
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform