Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Enhancement actual select to update all rows
Message
 
 
À
03/01/2013 09:58:06
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01561223
Message ID:
01561290
Vues:
38
>The following seems to work:
>
>
>UPDATE Menu2 SET Count=Temp.RecordCount FROM Menu AS Menu2 JOIN (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 DBUsers ON MenuEntity.NoEntity=DBUsers.NoEntity AND MenuPrivilege.NoType=DBUsers.NoType AND MenuRole.NoRole=DBUsers.NoRole
>WHERE Menu.Numero NOT IN (SELECT Menu.Numero FROM MenuPrivilegeExceptionCase
>INNER JOIN Menu ON MenuPrivilegeExceptionCase.NoMenu=Menu.Numero
>WHERE MenuPrivilegeExceptionCase.NoMember=DBUsers.AI)
>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 DBUsers ON MenuEntity.NoEntity=DBUsers.NoEntity
>WHERE MenuPrivilegeExceptionCase.NoMember=DBUsers.AI
>GROUP BY Menu.Numero) Temp ON Temp.Numero=Menu2.Numero
>
BTW, your UNION ALL select is going to return 2 rows for numero. So, which record count out of these two you want to use?

See related discussion here
http://social.msdn.microsoft.com/Forums/en/transactsql/thread/5adbafb9-0255-4122-9bed-0e712a012adf
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform